handlers

package
v2.8.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2021 License: MIT Imports: 9 Imported by: 0

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 v2.0.1

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL