server

package
v0.0.0-...-83625b3 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetParams

func GetParams(r *http.Request) httprouter.Params

GetParams returns the path parameter values from the request.

Types

type HandlerUnwrapper

type HandlerUnwrapper interface {
	Unwrap() http.Handler
}

type Server

type Server struct {
	Router *httprouter.Router

	Logger     log.Logger
	TLSConfig  *tls.Config
	HTTPServer *http.Server
	// contains filtered or unexported fields
}

Server is the main server struct.

func NewServer

func NewServer(config *config.Store, logger log.Logger) *Server

NewServer creates a new server with a database connection.

func (*Server) AddDynamicLocalDir

func (s *Server) AddDynamicLocalDir(prefix string, getPath func(*http.Request) http.FileSystem) *Server

func (*Server) AddFile

func (s *Server) AddFile(path, file string) *Server

AddFile adds a local file to the router.

func (*Server) AddStaticLocalDir

func (s *Server) AddStaticLocalDir(prefix, path string) *Server

AddStaticLocalDir adds a local directory to the router.

func (*Server) Delete

func (s *Server) Delete(path string, handler http.Handler, middlewares ...middleware.Middleware)

Delete adds a DELETE handler to the router.

func (*Server) DeleteF

func (s *Server) DeleteF(path string, handler http.HandlerFunc, middlewares ...middleware.Middleware)

DeleteF adds a DELETE HandlerFunc to the router.

func (*Server) EnableAutocert

func (s *Server) EnableAutocert(caDirEndpoint, cacheDir string, hostPolicy autocert.HostPolicy) error

EnableAutocert adds autocert to the server.

caDirEndpoint points to a ca directory endpoint. cacheDir defaults to "private/autocert-cache" when empty. If you use the recommended app layout, leave it empty. hostWhitelist is a list of hosts where the SSL certificate is valid. Supply at least one domain, else it won't work.

func (*Server) EnableLetsEncrypt

func (s *Server) EnableLetsEncrypt(cacheDir string, hostPolicy autocert.HostPolicy) error

EnableLetsEncrypt adds autocert to the server with LetsEncrypt CA dir.

See the documentation of EnableAutocert for cacheDir and hostPolicy.

func (*Server) Get

func (s *Server) Get(path string, handler http.Handler, middlewares ...middleware.Middleware)

Get adds a GET handler to the router.

func (*Server) GetF

func (s *Server) GetF(path string, handler http.HandlerFunc, middlewares ...middleware.Middleware)

GetF adds a GET HandlerFunc to the router.

func (*Server) GetServices

func (s *Server) GetServices() []Service

func (*Server) Handle

func (s *Server) Handle(method, path string, handler http.Handler, middlewares ...middleware.Middleware)

Handle adds a handler to the router.

The middleware list will be applied to this handler only.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler creates a http.Handler from the server (using the middlewares and the router).

func (*Server) Head

func (s *Server) Head(path string, handler http.Handler, middlewares ...middleware.Middleware)

Head adds a HEAD handler to the router.

func (*Server) HeadF

func (s *Server) HeadF(path string, handler http.HandlerFunc, middlewares ...middleware.Middleware)

HeadF adds a HEAD HandlerFunc to the router.

func (*Server) IsMaster

func (s *Server) IsMaster() bool

IsMaster tells if this server is in master mode.

See SetMaster()

func (*Server) Options

func (s *Server) Options(path string, handler http.Handler, middlewares ...middleware.Middleware)

Options adds an OPTIONS handler to the router.

func (*Server) OptionsF

func (s *Server) OptionsF(path string, handler http.HandlerFunc, middlewares ...middleware.Middleware)

OptionsF adds an OPTIONS HandlerFunc to the router.

func (*Server) Patch

func (s *Server) Patch(path string, handler http.Handler, middlewares ...middleware.Middleware)

Patch adds a PATCH handler to the router.

func (*Server) PatchF

func (s *Server) PatchF(path string, handler http.HandlerFunc, middlewares ...middleware.Middleware)

PatchF adds a PATCH HandlerFunc to the router.

func (*Server) Post

func (s *Server) Post(path string, handler http.Handler, middlewares ...middleware.Middleware)

Post adds a POST handler to the router.

func (*Server) PostF

func (s *Server) PostF(path string, handler http.HandlerFunc, middlewares ...middleware.Middleware)

PostF adds a POST HandlerFunc to the router.

func (*Server) Put

func (s *Server) Put(path string, handler http.Handler, middlewares ...middleware.Middleware)

Put adds a PUT handler to the router.

func (*Server) PutF

func (s *Server) PutF(path string, handler http.HandlerFunc, middlewares ...middleware.Middleware)

PutF adds a PUT HandlerFunc to the router.

func (*Server) RegisterService

func (s *Server) RegisterService(svc Service)

RegisterService adds a service on the server.

See the Service interface for more information.

func (*Server) SetMaster

func (s *Server) SetMaster()

SetMaster enables master mode on this server.

If a server is in master mode, it will execute SQL updates, and other potentially destructive operations. If you run a cluster, it is important that you either only run one master, or you deploy one master first, and the rest when all changes are finished.

func (*Server) StartHTTP

func (s *Server) StartHTTP(addr string) error

StartHTTP starts the server.

func (*Server) StartHTTPS

func (s *Server) StartHTTPS(addr, certFile, keyFile string) error

StartHTTPS starts the server.

func (*Server) Use

func (s *Server) Use(m middleware.Middleware)

Use adds middlewares to the top of the middleware stack.

func (*Server) UseF

func (s *Server) UseF(m func(http.Handler) http.Handler)

UseF adds a middleware function to the top of the middleware stack.

func (*Server) UseHandler

func (s *Server) UseHandler(h http.Handler)

UseHandler uses a http.Handler as a middleware.

func (*Server) UseTop

func (s *Server) UseTop(m middleware.Middleware)

UseTop adds middlewares to the bottom of the middleware stack.

func (*Server) UseTopF

func (s *Server) UseTopF(m func(http.Handler) http.Handler)

UseTopF adds a middleware function to the bottom of the middleware stack.

type Service

type Service interface {
	// Name returns the name of this service instance.
	Name() string
	// Register the Service endpoints
	Register(*Server) error
}

Service is a collection of endpoints that logically belong together or operate on the same part of the database schema.

type ServiceName

type ServiceName string

func (ServiceName) Name

func (n ServiceName) Name() string

Jump to

Keyboard shortcuts

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