Documentation ¶
Index ¶
- Constants
- Variables
- func ExecuteFunc(ctx context.Context, fn, param interface{}, cType contentType) (interface{}, bool, error)
- func Handler(fn, param interface{}, cType contentType) (http.Handler, error)
- func Render(w http.ResponseWriter, data interface{}, cType contentType)
- func ReqBodyHandler(fn interface{}, cType contentType) (http.Handler, error)
Constants ¶
const ( JSON contentType = iota HALJSON )
Variables ¶
var DefaultResponse = json.RawMessage(`{"message":"ok"}`)
var ErrBadRequest = errors.New("bad request")
Functions ¶
func ExecuteFunc ¶
func ExecuteFunc(ctx context.Context, fn, param interface{}, cType contentType) (interface{}, bool, error)
ExecuteFunc executes the fn with the param after checking whether the function signature is valid or not by calling Handler. The first return value is the result that fn returns. The second return value is a boolean indicating whether the caller should panic on the err or not. If it's true, it means the caller can process the error normally; if it's false, it means the caller should probably panic on the error. The third return value is an error either from Handler() or from fn, if any.
func Handler ¶
Handler returns an HTTP Handler for function fn. If fn returns a non-nil error, the handler will use problem.Render. Please refer to funcParamType for the allowed function signature. The caller of this function should probably panic on the returned error, if any.
func Render ¶
func Render(w http.ResponseWriter, data interface{}, cType contentType)
Render write data to w, after marshalling to json. The response header is set based on cType.
func ReqBodyHandler ¶
ReqBodyHandler returns an HTTP Handler for function fn. If fn has an input type, it will try to decode the request body into the function's input type. If fn returns a non-nil error, the handler will use problem.Render. Please refer to funcParamType for the allowed function signature. The caller of this function should probably panic on the returned error, if any.
Types ¶
This section is empty.