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 Domain
- func (domain *Domain) Delete(path string, handler Handler)
- func (domain *Domain) Get(path string, handler Handler)
- func (domain *Domain) Options(path string, handler Handler)
- func (domain *Domain) Post(path string, handler Handler)
- func (domain *Domain) ProxyLocalAssets(destAddress string)
- func (domain *Domain) Put(path string, handler Handler)
- func (domain *Domain) ServeFiles(path string, root http.FileSystem)
- type Handler
- type ReplyOption
- type Server
- func (s *Server) Delete(path string, handler Handler)
- func (s *Server) Domain(host string) *Domain
- func (s *Server) Get(path string, handler Handler)
- func (s *Server) Options(path string, handler Handler)
- func (s *Server) Post(path string, handler Handler)
- func (s *Server) ProxyLocalAssets(destAddress string)
- func (s *Server) Put(path string, handler Handler)
- func (s *Server) ServeFiles(path string, root http.FileSystem)
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- 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 Domain ¶ added in v1.56.0
type Domain struct {
// contains filtered or unexported fields
}
func (*Domain) ProxyLocalAssets ¶ added in v1.61.0
func (*Domain) ServeFiles ¶ added in v1.56.0
func (domain *Domain) ServeFiles(path string, root http.FileSystem)
ServeFiles register a raw net/http handler with no error checking that sends files.
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.
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 Server ¶
type Server struct {
// 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.
func (*Server) ProxyLocalAssets ¶ added in v1.61.0
func (*Server) ServeFiles ¶ added in v1.56.0
func (s *Server) ServeFiles(path string, root http.FileSystem)
ServeFiles register a raw net/http handler with no error checking that sends files.
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 WithLogrus ¶
func WithLogrus() ServerOption
WithLogrus enables logging of the errors of the handlers.
func WithSentry ¶
func WithSentry(dsn string) ServerOption
WithSentry configures Sentry logging of issues in the handlers.