wrappers

package
v0.0.0-...-c5b96c6 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const AcceptKey = "accept"
View Source
const ContentTypeKey = "content-type"

Variables

View Source
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

View Source
var DefaultValidateHandler = govalidator.ValidateStruct

DefaultValidateHandler ValidateHandler used if no validation handling argument is passed to BuildEndpoint

Functions

func GetTypes

func GetTypes(fn interface{}) (input, output reflect.Type)

GetTypes fetches the associated input and output types for a supported handler function

Types

type Decoder

type Decoder func(method string, req *http.Request, input interface{}) error

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

type Encoder func(rw http.ResponseWriter, req *http.Request, output interface{}, status int) error

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

type ValidateHandler func(s interface{}) (bool, error)

ValidateHandler provides structure field validation

Jump to

Keyboard shortcuts

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