Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Config = Configuration{ StringsExtractors: []extractor.Strings{extractor.Path{}, extractor.Header{}, extractor.Query{}}, ValueExtractors: []extractor.Value{extractor.Context{}}, ErrorHook: hook.Error, RenderHook: hook.Render, BindHook: hook.Bind(256 * 1024), ValidateHook: hook.Validate, LogHook: hook.Log, }
Config is the instance of Configuration type. You can add as many extractor you want, modify them ... You can set your custom hook too.
var ErrStopHandler = errors.New("KCD_STOP_HANDLER")
ErrStopHandler will stop execution of the handler, a blank response will be sent
Functions ¶
func Handler ¶
func Handler(h interface{}, defaultStatusCode int) http.HandlerFunc
Handler returns a default http handler.
The handler may use the following signature:
func( [ctx context.Context], [response http.ResponseWriter], [request *http.Request], [INPUT object ptr]) ([OUTPUT object], error)
INPUT and OUTPUT struct are both optional. As such, the minimal accepted signature is:
func() error
There is an exception because you can also use default http handler but the status code, and the render hook will not be used.
A complete example for an INPUT struct:
type CreateCustomerInput struct { Name string `path:"name"` // /some-path/{name} Authorization string `header:"X-authorization"` // header name 'X-authorization' Emails []string `query:"emails" exploder:","` // /some-path/{name}?emails=a@1.fr,b@1.fr Body map[string]string `json:"body"` // json body with {body: {a: "hey", b: "hoy"}} ContextualID *struct { ID string `ctx:"id" default:"robot"` // ctx value with key 'id' or it will default set ID to "robot" } }
The wrapped handler will bind the parameters from the query-string, path, body and headers, context, and handle the errors.
Handler will panic if the kcd handler or its input/output values are of incompatible type.
Types ¶
type Configuration ¶
type Configuration struct { StringsExtractors []extractor.Strings ValueExtractors []extractor.Value ErrorHook hook.ErrorHook BindHook hook.BindHook ValidateHook hook.ValidateHook RenderHook hook.RenderHook LogHook hook.LogHook Verbose bool }
Configuration is the main configuration type of kcd.