Documentation ¶
Index ¶
Constants ¶
View Source
const ( // Megabyte is a pre-defined maximum payload size that can be used in // NewBaseHandler Megabyte = 1024 * 1024 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseHandler ¶
type BaseHandler interface { tracing.Tracer // Read reads the body and tries to decode JSON from it to the given output type Parse(r *http.Request, out interface{}) error // Write writes the response serving the given object as JSON with the given status Write(ctx context.Context, w http.ResponseWriter, status int, obj interface{}) // Error serves the proper error object based on the given error and its type Error(context.Context, http.ResponseWriter, error) }
BaseHandler contains all the base functions every handler should have
func NewBaseHandler ¶
func NewBaseHandler(componentName string, maxBodyBytes int64, debug bool) BaseHandler
NewBaseHandler creates a new base HTTP handler that contains shared logic among all the handlers. The handler supports parsing and writing JSON objects `maxBodyBytes` is the maximal request body size, < 0 means the default Megabyte. `componentName` is used for tracing to identify to which component this handler belongs to.
func NewBaseHandlerWithTracer ¶ added in v1.5.4
func NewBaseHandlerWithTracer(tracer tracing.Tracer, maxBodyBytes int64, debug bool) BaseHandler
NewBasehandlerWithTracer create a new base HTTP handler, like NewBaseHandler, but allows the caller to configure the Tracer implementation independently.
Click to show internal directories.
Click to hide internal directories.