Documentation ¶
Index ¶
- func BadRequest(s string, args ...interface{}) error
- func Internal(s string, args ...interface{}) error
- func Lang(r *http.Request) string
- func LangFromContext(ctx context.Context) string
- func NotFound(s string, args ...interface{}) error
- func Param(r *http.Request, name string) string
- func RequestFromContext(ctx context.Context) *http.Request
- func Unauthorized(s string, args ...interface{}) error
- type Error
- type Group
- type Handler
- type Server
- func (s *Server) Delete(lang, path string, handler Handler)
- func (s *Server) Get(lang, path string, handler Handler)
- func (s *Server) Group(g Group)
- func (s *Server) Options(lang, path string, handler Handler)
- func (s *Server) Post(lang, path string, handler Handler)
- func (s *Server) Put(lang, path string, handler Handler)
- func (s *Server) Router() *httprouter.Router
- type ServerOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BadRequest ¶
BadRequest returns a 400 HTTP error and formats its message.
func LangFromContext ¶
LangFromContext returns the lang of the route linked to the request in the routing table. The context must have been previously extracted from r.Context().
func RequestFromContext ¶
RequestFromContext returns the HTTP request from a context. The context must have been previously extracted from r.Context().
func Unauthorized ¶
Unauthorized returns a 401 HTTP error and formats its message.
Types ¶
type Group ¶
type Group struct { // Handler that will be called for all langs. Handler Handler // HTTP method to use. If empty or unknown it will use "GET". Method string // Map of language -> URL that should be registered. URL map[string]string }
Group registers multiple URLs for each lang for the same handler.
func GroupFromContext ¶
GroupFromContext returns the context of the request. If the route was direct and used no group it returns an empty group with no URLs.
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 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) Router ¶
func (s *Server) Router() *httprouter.Router
Router returns the raw underlying router to make advanced modifications. If you modify the NotFound handler remember to call routing.NotFoundHandler as fallback if you don't want to process the request.
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.