Documentation
¶
Index ¶
Constants ¶
const AcceptKey = "accept"
const ContentTypeKey = "content-type"
Variables ¶
var DefaultErrorHandler = func(ctx interface{}, rw http.ResponseWriter, req *http.Request, code int, format string, args ...interface{}) { rw.WriteHeader(code) msg := fmt.Sprintf(format, args) log.Warningln(msg) rw.Write([]byte(msg)) }
DefaultErrorHandler ErrorHandler used if no error handling argument is passed to BuildEndpoint
var DefaultValidateHandler = govalidator.ValidateStruct
DefaultValidateHandler ValidateHandler used if no validation handling argument is passed to BuildEndpoint
Functions ¶
Types ¶
type Decoder ¶
Decoder handles decoding of a request body into the provided interface based on the provided type
var DefaultDecoder Decoder = decodeRequest
DefaultDecoder Decoder used if no decoder argument is passed to BuildEndpoint
type Encoder ¶
Encoder handles the encoding of a provided interface into an accepted form
var DefaultEncoder Encoder = encodeResponse
DefaultEncoder Encoder used if no encoder argument is passed to BuildEndpoint
type ErrorHandler ¶
type ErrorHandler func(ctx interface{}, rw http.ResponseWriter, req *http.Request, code int, format string, args ...interface{})
ErrorHandler type for handling errors in wrapped functions or encoders/decoders
type HTTPHandler ¶
type HTTPHandler func(ctx interface{}, rw http.ResponseWriter, req *http.Request)
HTTPHandler is a standard http endpoint handler for binding into a http mux
func BuildEndpoint ¶
func BuildEndpoint(method string, fn interface{}, args ...interface{}) (HTTPHandler, error)
BuildEndpoint Build and return and endpoint handler for the provided function and method Supports handler functions with (i InputType), (i InputType, h http.Header) or (ctx interface{}, i InputType, http.header) input parameters and (OutputType, error), (OutputType, int, error) or (OutputType, int, http.Header, error) output parameters where int is a http.Status code. args may include an ErrorHandler to override the DefaultError handler.
type ValidateHandler ¶
ValidateHandler provides structure field validation