Documentation ¶
Index ¶
- Variables
- func ErrorBadRequest(err error) error
- func ErrorInternalServerError(err error) error
- func ErrorNotFound(err error) error
- func ExtractAndCall(target interface{}, w http.ResponseWriter, r *http.Request, ...)
- func ExtractAndCallWithBody(target interface{}, body interface{}, w http.ResponseWriter, r *http.Request, ...)
- func ExtractParameters(target interface{}, r *http.Request, params httprouter.Params) error
- func Map(tag string, source Source, target interface{}) error
- func RegisterSignalHandlerForServer(server *http.Server) <-chan struct{}
- func WriteBody(writer http.ResponseWriter, statusCode int, contentType string, content []byte)
- func WriteError(writer http.ResponseWriter, status int, err error)
- func WriteErrorContext(ctx context.Context, writer http.ResponseWriter, status int, err error)
- func WriteGenericError(w http.ResponseWriter, err error)
- func WriteJSON(w http.ResponseWriter, status int, value interface{})
- func WriteResponseValue(w http.ResponseWriter, value interface{}, err error)
- type Config
- type ErrorResponse
- type HTTPOptions
- type HttpMiddleware
- type HttpRouterMiddleware
- type MapSource
- type ResponseValue
- type Setter
- type Source
Constants ¶
This section is empty.
Variables ¶
Type registry for custom setters. Only modify in your modules init function.
View Source
var ErrorMapper = func(err error) int { switch errors.Cause(err) { case sql.ErrNoRows: return http.StatusNotFound default: return http.StatusInternalServerError } }
Functions ¶
func ErrorBadRequest ¶
func ErrorNotFound ¶
func ExtractAndCall ¶
func ExtractAndCall(target interface{}, w http.ResponseWriter, r *http.Request, params httprouter.Params, handler func() (interface{}, error))
Extracts and validates the path and request parameters before calling the given method.
func ExtractAndCallWithBody ¶
func ExtractAndCallWithBody( target interface{}, body interface{}, w http.ResponseWriter, r *http.Request, params httprouter.Params, handler func() (interface{}, error))
Parses the body, path and request parameters and then calls the given handler function.
func ExtractParameters ¶
func ExtractParameters(target interface{}, r *http.Request, params httprouter.Params) error
Parses the 'path' parameters as well as the 'query' parameters into the given object. Returns an error, if parsing failed.
func WriteBody ¶
func WriteBody(writer http.ResponseWriter, statusCode int, contentType string, content []byte)
func WriteError ¶
func WriteError(writer http.ResponseWriter, status int, err error)
func WriteErrorContext ¶
func WriteGenericError ¶
func WriteGenericError(w http.ResponseWriter, err error)
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, status int, value interface{})
func WriteResponseValue ¶
func WriteResponseValue(w http.ResponseWriter, value interface{}, err error)
Types ¶
type Config ¶
type Config struct { // name for the service. Will be used in the admin panel Name string // Routing configuration. You can use the supplied router or // return your own handler. Routing func(*httprouter.Router) http.Handler // Extra admin handlers to register on the admin page AdminHandlers []admin.RouteConfig // Registers a shutdown handler for the http server. If not set, // a default signal handler for clean shutdown on SIGINT and SIGTERM is used. RegisterSignalHandlerForServer func(*http.Server) <-chan struct{} // Wrap the http server with this middleware in the end. A good example would // be to use a tracing middleware at this point. UseMiddleware HttpMiddleware }
type ErrorResponse ¶
func (ErrorResponse) Error ¶
func (err ErrorResponse) Error() string
type HTTPOptions ¶
type HTTPOptions struct { Address string `long:"http-address" default:":3080" description:"Address to listen on."` TLSKeyFile string `long:"http-tls-key" description:"Private key file to enable SSL support."` TLSCertFile string `long:"http-tls-cert" description:"Certificate file to enable SSL support."` BasicAuthUsername string `long:"http-admin-username" default:"admin" description:"Basic auth username for admin panel."` BasicAuthPassword string `long:"http-admin-password" default:"bingo" description:"Basic auth password for admin panel."` AccessLog string `long:"http-access-log" description:"Write http access log to a file. Defaults to stdout."` }
func (HTTPOptions) Serve ¶
func (opts HTTPOptions) Serve(config Config)
type HttpMiddleware ¶
func AdaptMiddlewareForHttp ¶
func AdaptMiddlewareForHttp(middleware HttpRouterMiddleware) HttpMiddleware
Takes a httprouter.Handle middleware and wraps it so it can be used with http.Handler functions.
type HttpRouterMiddleware ¶
type HttpRouterMiddleware func(httprouter.Handle) httprouter.Handle
func AdaptMiddlewareForHttpRouter ¶
func AdaptMiddlewareForHttpRouter(w HttpMiddleware) HttpRouterMiddleware
Takes a normal http.Handler middleware and wraps it so it can be used with httprouter.Handle functions.
type ResponseValue ¶
Click to show internal directories.
Click to hide internal directories.