Documentation ¶
Overview ¶
Package routing sends requests to handlers and process the errors.
Index ¶
- func BadRequest(s string) error
- func BadRequestf(s string, args ...interface{}) error
- func Internal(s string) error
- func Internalf(s string, args ...interface{}) error
- func JSON(w http.ResponseWriter, reply interface{}, opts ...ReplyOption) error
- func NotFound(s string) error
- func NotFoundf(s string, args ...interface{}) error
- func Param(r *http.Request, name string) string
- func RequestFromContext(ctx context.Context) *http.Request
- func Unauthorized(s string) error
- func Unauthorizedf(s string, args ...interface{}) error
- type Handler
- type Middleware
- type ReplyOption
- type Router
- func (router *Router) Delete(path string, handler Handler)
- func (router *Router) Domain(host string, opts ...RouterOption) *Router
- func (router *Router) Get(path string, handler Handler)
- func (router *Router) Head(path string, handler Handler)
- func (router *Router) Header(header, value string, opts ...RouterOption) *Router
- func (router *Router) Options(path string, handler Handler)
- func (router *Router) PathPrefix(path string, opts ...RouterOption) *Router
- func (router *Router) PathPrefixHandler(pathPrefix string, handler Handler)
- func (router *Router) Post(path string, handler Handler)
- func (router *Router) ProxyLocalAssets(destAddress string)
- func (router *Router) Put(path string, handler Handler)
- func (router *Router) ServeFiles(path string, root http.FileSystem)
- type RouterOption
- type Server
- type ServerOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BadRequestf ¶ added in v1.49.0
BadRequestf returns a 400 HTTP error and formats its message.
func JSON ¶ added in v1.59.0
func JSON(w http.ResponseWriter, reply interface{}, opts ...ReplyOption) error
func RequestFromContext ¶
RequestFromContext returns the HTTP request from a context. The context must have been previously extracted from r.Context().
func Unauthorizedf ¶ added in v1.49.0
Unauthorizedf returns a 401 HTTP error and formats its message.
Types ¶
type Handler ¶
type Handler func(w http.ResponseWriter, r *http.Request) error
Handler should be implemented by the handler functions that we want to register.
func NewHandlerFromHTTP ¶ added in v1.109.0
NewHandlerFromHTTP creates a new handler from a standard http.Handler.
type Middleware ¶ added in v1.84.0
type ReplyOption ¶ added in v1.59.0
type ReplyOption func(w http.ResponseWriter)
func WithStatus ¶ added in v1.59.0
func WithStatus(statusCode int) ReplyOption
type Router ¶ added in v1.83.0
type Router struct {
// contains filtered or unexported fields
}
func (*Router) Domain ¶ added in v1.83.0
func (router *Router) Domain(host string, opts ...RouterOption) *Router
Domain matches a hostname.
func (*Router) Header ¶ added in v1.106.0
func (router *Router) Header(header, value string, opts ...RouterOption) *Router
Header matches a header with a specific value. If the value is empty it will match any value as long as the header is present in the request.
func (*Router) PathPrefix ¶ added in v1.83.0
func (router *Router) PathPrefix(path string, opts ...RouterOption) *Router
PathPrefix matches a path prefix.
func (*Router) PathPrefixHandler ¶ added in v1.109.0
func (*Router) ProxyLocalAssets ¶ added in v1.83.0
func (*Router) ServeFiles ¶ added in v1.83.0
func (router *Router) ServeFiles(path string, root http.FileSystem)
ServeFiles register a raw net/http handler with no error checking that sends files.
type RouterOption ¶ added in v1.84.0
type RouterOption func(router *Router)
func WithCORS ¶ added in v1.109.0
func WithCORS(opts cors.Options) RouterOption
WithCORS configures a CORS middleware to authorize cross-origin requests.
func WithMiddleware ¶ added in v1.84.0
func WithMiddleware(middleware Middleware) RouterOption
WithMiddleware adds a middleware to the router.
type Server ¶
type Server struct { *Router // contains filtered or unexported fields }
Server configures the routing table.
func NewServer ¶
func NewServer(opts ...ServerOption) *Server
NewServer configures a new router with the options.
type ServerOption ¶
type ServerOption func(server *Server)
ServerOption is implement by any option that can be passed when constructing a new server.
func WithBetaAuth ¶
func WithBetaAuth(username, password string) ServerOption
WithBetaAuth installs a rough authentication mechanism to avoid the final users to access beta sites.
func WithCustom404 ¶
func WithCustom404(handler Handler) ServerOption
WithCustom404 uses a custom 404 template file.
func WithCustomTimeout ¶ added in v1.89.1
func WithCustomTimeout(timeout time.Duration) ServerOption
WithCustomTimeout changes the default timeout of 29 seconds to a custom one. It's only recommended for environments where the limit is longer than 30-60 seconds. For example background queues might have 10 minutes of activity in some setups.
func WithSentry ¶
func WithSentry(dsn string) ServerOption
WithSentry configures Sentry logging of issues in the handlers.