Documentation
¶
Index ¶
- Variables
- func Error(w http.ResponseWriter, r *http.Request, err error, logger LogHook)
- func Log(_ http.ResponseWriter, r *http.Request, err error)
- func Render(w http.ResponseWriter, _ *http.Request, response interface{}, statusCode int) error
- func Validate(ctx context.Context, input interface{}) error
- type BindHook
- type ErrorHook
- type ErrorResponse
- type LogHook
- type RenderHook
- type ValidateHook
Constants ¶
This section is empty.
Variables ¶
var ErrorHookStatusCodeMinLogged = 500
Functions ¶
func Error ¶
Error is the default error hook. It check the error and return the corresponding response to the client. logger parameter is optional (you can set it to nil)
Types ¶
type BindHook ¶
type BindHook func(w http.ResponseWriter, r *http.Request, in interface{}) error
BindHook is the hook called by the wrapped http handler when binding an incoming request to the kcd handler's input object.
type ErrorHook ¶
ErrorHook hook lets you interpret errors returned by your handlers. After analysis, the hook should return a suitable http status code and and error payload. This lets you deeply inspect custom error types.
type ErrorResponse ¶
type ErrorResponse struct {
ErrorDescription string `json:"error_description"`
Error errors.Kind `json:"error"`
Fields map[string]string `json:"fields,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
ErrorResponse is the default response that send the default error hook.
type LogHook ¶
type LogHook func(w http.ResponseWriter, r *http.Request, err error)
LogHook is the logger triggered after the error hook. It can show detailed error about a problem that you can't explain to users.
type RenderHook ¶
type RenderHook func(w http.ResponseWriter, r *http.Request, response interface{}, defaultStatusCode int) error
RenderHook is the last hook called by the wrapped handler before returning. It takes the response, request, the success HTTP status code and the response payload as parameters.
Its role is to render the payload to the client to the proper format.
type ValidateHook ¶
ValidateHook is the hook called to validate the input. The default expected return (handled by the error hook) is a map[string]error.