routing

package
v1.66.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2020 License: MIT Imports: 13 Imported by: 5

Documentation

Overview

Package routing sends requests to handlers and process the errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(s string) error

BadRequest returns a 400 HTTP error.

func BadRequestf added in v1.49.0

func BadRequestf(s string, args ...interface{}) error

BadRequestf returns a 400 HTTP error and formats its message.

func Internal

func Internal(s string) error

Internal returns a 500 HTTP error.

func Internalf added in v1.49.0

func Internalf(s string, args ...interface{}) error

Internalf returns a 500 HTTP error and formats its message.

func JSON added in v1.59.0

func JSON(w http.ResponseWriter, reply interface{}, opts ...ReplyOption) error

func NotFound

func NotFound(s string) error

NotFound returns a 404 HTTP error.

func NotFoundf added in v1.49.0

func NotFoundf(s string, args ...interface{}) error

NotFoundf returns a 404 HTTP error and formats its message.

func Param

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

Param returns a request URL parameter value.

func RequestFromContext

func RequestFromContext(ctx context.Context) *http.Request

RequestFromContext returns the HTTP request from a context. The context must have been previously extracted from r.Context().

func Unauthorized

func Unauthorized(s string) error

Unauthorized returns a 401 HTTP error.

func Unauthorizedf added in v1.49.0

func Unauthorizedf(s string, args ...interface{}) error

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) Delete added in v1.56.0

func (domain *Domain) Delete(path string, handler Handler)

Delete registers a new DELETE route in the domain.

func (*Domain) Get added in v1.56.0

func (domain *Domain) Get(path string, handler Handler)

Get registers a new GET route in the domain.

func (*Domain) Options added in v1.56.0

func (domain *Domain) Options(path string, handler Handler)

Options registers a new OPTIONS route in the domain.

func (*Domain) Post added in v1.56.0

func (domain *Domain) Post(path string, handler Handler)

Post registers a new POST route in the domain.

func (*Domain) ProxyLocalAssets added in v1.61.0

func (domain *Domain) ProxyLocalAssets(destAddress string)

func (*Domain) Put added in v1.56.0

func (domain *Domain) Put(path string, handler Handler)

Put registers a new PUT route in the domain.

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

func (s *Server) Delete(path string, handler Handler)

Delete registers a new DELETE route in the router.

func (*Server) Domain added in v1.56.0

func (s *Server) Domain(host string) *Domain

func (*Server) Get

func (s *Server) Get(path string, handler Handler)

Get registers a new GET route in the router.

func (*Server) Options added in v1.16.0

func (s *Server) Options(path string, handler Handler)

Options registers a new OPTIONS route in the router.

func (*Server) Post

func (s *Server) Post(path string, handler Handler)

Post registers a new POST route in the router.

func (*Server) ProxyLocalAssets added in v1.61.0

func (s *Server) ProxyLocalAssets(destAddress string)

func (*Server) Put

func (s *Server) Put(path string, handler Handler)

Put registers a new PUT route in the router.

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.

func (*Server) ServeHTTP added in v1.56.0

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.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.

Jump to

Keyboard shortcuts

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