Documentation ¶
Index ¶
- func CORSMiddleware(origins, methods, headers string) func(h http.Handler) http.Handler
- func PathArg(r *http.Request, name string) string
- func RecoverMiddleware() func(http.Handler) http.Handler
- func RequestIDMiddleware() func(http.Handler) http.Handler
- func TrailingSlashMiddleware(requiredTrailingSlash bool) func(http.Handler) http.Handler
- func WithPathArg(ctx context.Context, names []string, values []string) context.Context
- func WriteJSON(w http.ResponseWriter, code int, content interface{})
- func WriteJSONErr(w http.ResponseWriter, code int, message string)
- func WriteJSONStdErr(w http.ResponseWriter, code int)
- type Router
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CORSMiddleware ¶
CORSMiddleware retunrs a middleware to enable Cross-Origin Resource Sharing (CORS) for provided configuration.
Origins is a list of comma separated domain list that controls which domains are allowed. Localhost is always allowed.
Methods allows to enable certain method execution. Use * for all/any wildcard.
Header allows to enable certain header sending. Use * for all/any wildcard.
func PathArg ¶
PathArg returns the string representation of a named match, extracted from the URL path.
This function panics if used for a arg name that is not defined for that route.
func RecoverMiddleware ¶
RecoverMiddleware captures any panic, emits an alert event for it and writes 500 response code.
func TrailingSlashMiddleware ¶
TrailingSlashMiddleware enforce all URLs to a single format of always either having a trailign slash or not.
func WithPathArg ¶
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, code int, content interface{})
func WriteJSONErr ¶
func WriteJSONErr(w http.ResponseWriter, code int, message string)
func WriteJSONStdErr ¶
func WriteJSONStdErr(w http.ResponseWriter, code int)
Types ¶
type Router ¶
type Router struct { MethodNotAllowed http.Handler NotFound http.Handler // contains filtered or unexported fields }
func (*Router) Use ¶
Use registers middlewares to be used for all endpoints. Middlewares are executed in order they are provided. If Use is called multiple times, middlewares are added in the following order:
router.Add(A, B, C) router.Add(D, E, F) Request >> D E F A B C >> handler >> C B A F E D >>