func (srv *Server) Handle(f interface{}) Handler {
	fv := reflect.ValueOf(f)
	hf, err := srv.handlerFunc(fv.Type(), nil)
	if err != nil {
		panic(errgo.Notef(err, "bad handler function"))
	}
	return Handler{
		Method: hf.method,
		Path:   hf.pathPattern,
		Handle: func(w http.ResponseWriter, req *http.Request, p httprouter.Params) {
			ctx := req.Context()
			p1 := Params{
				Response:    w,
				Request:     req,
				PathVar:     p,
				PathPattern: hf.pathPattern,
				Context:     ctx,
			}
			argv, err := hf.unmarshal(p1)
			if err != nil {
				srv.WriteError(ctx, w, err)
				return
			}
			hf.call(fv, argv, p1)
		},
	}
}
// Handle converts a function into a Handler. The argument f
// must be a function of one of the following six forms, where ArgT
// must be a struct type acceptable to Unmarshal and ResultT is a type
// that can be marshaled as JSON:
//
//	func(p Params, arg *ArgT)
//	func(p Params, arg *ArgT) error
//	func(p Params, arg *ArgT) (ResultT, error)
//
//	func(arg *ArgT)
//	func(arg *ArgT) error
//	func(arg *ArgT) (ResultT, error)
//
// When processing a call to the returned handler, the provided
// parameters are unmarshaled into a new ArgT value using Unmarshal,
// then f is called with this value. If the unmarshaling fails, f will
// not be called and the unmarshal error will be written as a JSON
// response.
//
// As an additional special case to the rules defined in Unmarshal, the
// tag on an anonymous field of type Route specifies the method and path
// to use in the HTTP request. It should hold two space-separated
// fields; the first specifies the HTTP method, the second the URL path
// to use for the request. If this is given, the returned handler will
// hold that method and path, otherwise they will be empty.
//
// If an error is returned from f, it is passed through the error mapper
// before writing as a JSON response.
//
// In the third form, when no error is returned, the result is written
// as a JSON response with status http.StatusOK. Also in this case, any
// calls to Params.Response.Write or Params.Response.WriteHeader will be
// ignored, as the response code and data should be defined entirely by
// the returned result and error.
//
// Handle will panic if the provided function is not in one of the above
// forms.
Handle converts a function into a Handler. The argument f
must be a function of one of the following six forms, where ArgT
must be a struct type acceptable to Unmarshal and ResultT is a type
that can be marshaled as JSON.

func(p Params, arg *ArgT)
func(p Params, arg *ArgT) error
func(p Params, arg *ArgT) (ResultT, error)

func(arg *ArgT)
func(arg *ArgT) error
func(arg *ArgT) (ResultT, error)

When processing a call to the returned handler, the provided
parameters are unmarshaled into a new ArgT value using Unmarshal,
then f is called with this value. If the unmarshaling fails, f will
not be called and the unmarshal error will be written as a JSON
response.

As an additional special case to the rules defined in Unmarshal, the
tag on an anonymous field of type Route specifies the method and path
to use in the HTTP request. It should hold two space-separated
fields; the first specifies the HTTP method, the second the URL path
to use for the request. If this is given, the returned handler will
hold that method and path, otherwise they will be empty.

If an error is returned from f, it is passed through the error mapper
before writing as a JSON response.

In the third form, when no error is returned, the result is written
as a JSON response with status http.StatusOK. Also in this case, any
calls to Params.Response.Write or Params.Response.WriteHeader will be
ignored, as the response code and data should be defined entirely by
the returned result and error.

Handle will panic if the provided function is not in one of the above
forms.
// Handle converts a function into a Handler . The argument f // must be a function of one of the following six forms where ArgT // must be a struct type acceptable to Unmarshal and ResultT is a type // that can be marshaled as JSON : // // func ( p Params arg * ArgT ) // func ( p Params arg * ArgT ) error // func ( p Params arg * ArgT ) ( ResultT error ) // // func ( arg * ArgT ) // func ( arg * ArgT ) error // func ( arg * ArgT ) ( ResultT error ) // // When processing a call to the returned handler the provided // parameters are unmarshaled into a new ArgT value using Unmarshal // then f is called with this value . If the unmarshaling fails f will // not be called and the unmarshal error will be written as a JSON // response . // // As an additional special case to the rules defined in Unmarshal the // tag on an anonymous field of type Route specifies the method and path // to use in the HTTP request . It should hold two space - separated // fields ; the first specifies the HTTP method the second the URL path // to use for the request . If this is given the returned handler will // hold that method and path otherwise they will be empty . // // If an error is returned from f it is passed through the error mapper // before writing as a JSON response . // // In the third form when no error is returned the result is written // as a JSON response with status http . StatusOK . Also in this case any // calls to Params . Response . Write or Params . Response . WriteHeader will be // ignored as the response code and data should be defined entirely by // the returned result and error . // // Handle will panic if the provided function is not in one of the above // forms .
func (srv *Server) Handle(f interface{}) Handler {
	fv := reflect.ValueOf(f)
	hf, err := srv.handlerFunc(fv.Type(), nil)
	if err != nil {
		panic(errgo.Notef(err, "bad handler function"))
	}
	return Handler{
		Method: hf.method,
		Path:   hf.pathPattern,
		Handle: func(w http.ResponseWriter, req *http.Request, p httprouter.Params) {
			ctx := req.Context()
			p1 := Params{
				Response:    w,
				Request:     req,
				PathVar:     p,
				PathPattern: hf.pathPattern,
				Context:     ctx,
			}
			argv, err := hf.unmarshal(p1)
			if err != nil {
				srv.WriteError(ctx, w, err)
				return
			}
			hf.call(fv, argv, p1)
		},
	}
}
func ( srv * Server ) Handle ( f interface { } ) Handler { fv := reflect . ValueOf ( f ) hf , err := srv . handlerFunc ( fv . Type ( ) , nil ) if err != nil { panic ( errgo . Notef ( err , " " ) ) } return Handler { Method : hf . method , Path : hf . pathPattern , Handle : func ( w http . ResponseWriter , req * http . Request , p httprouter . Params ) { ctx := req . Context ( ) p1 := Params { Response : w , Request : req , PathVar : p , PathPattern : hf . pathPattern , Context : ctx , } argv , err := hf . unmarshal ( p1 ) if err != nil { srv . WriteError ( ctx , w , err ) return } hf . call ( fv , argv , p1 ) } , } }
Handle converts a function into a Handler.
Handle converts a function into a Handler .