web

package
v0.0.0-...-83cf971 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: LGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORSMiddleware

func CORSMiddleware(origins, methods, headers string) func(h http.Handler) http.Handler

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.

https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

func PathArg

func PathArg(r *http.Request, name string) string

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

func RecoverMiddleware() func(http.Handler) http.Handler

RecoverMiddleware captures any panic, emits an alert event for it and writes 500 response code.

func RequestIDMiddleware

func RequestIDMiddleware() func(http.Handler) http.Handler

func TrailingSlashMiddleware

func TrailingSlashMiddleware(requiredTrailingSlash bool) func(http.Handler) http.Handler

TrailingSlashMiddleware enforce all URLs to a single format of always either having a trailign slash or not.

func WithPathArg

func WithPathArg(ctx context.Context, names []string, values []string) context.Context

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 NewRouter

func NewRouter() *Router

func (*Router) Add

func (rt *Router) Add(routeConf string, handler interface{})

func (Router) ServeHTTP

func (rt Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Router) Use

func (rt *Router) Use(middlewares ...func(http.Handler) http.Handler)

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

Jump to

Keyboard shortcuts

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