Documentation
¶
Overview ¶
Package server provides an HTTP server implementation that wraps the http.Server from the stdlib, and a Router interface for implementing routing.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
*Server
// Prefix defines the router prefix to register the API routes against.
Prefix string
// contains filtered or unexported fields
}
API wraps the Server struct, and uses a separate mux.Router for serving routes for the API.
type Router ¶
type Router interface {
// RegisterUI will register the router's UI routes with the given
// mux.Router. It will also pass through the CSRF middleware function, and
// a variadic list of gates to apply to the routes being registered.
RegisterUI(*mux.Router, func(http.Handler) http.Handler, ...web.Gate)
// RegisterAPI will register the router's API routes with the given
// mux.Router. Unlike RegisterUI, this does not take a CSRF middleware
// function, and only the variadic list of gates.
RegisterAPI(string, *mux.Router, ...web.Gate)
}
Router defines how a router should be implemented to be used for the Server. It is perfectly valid for the RegisterUI or RegisterAPI methods to be simple stubs to statisfy the interface is a Router doesn't need to expose either via the Server.
type Server ¶
type Server struct {
*http.Server
Log *log.Logger // Log is the logger to use for application logging.
Router *mux.Router // Router is the mux.Router to use for registering routes.
Routers map[string]Router // Routers defines the routers for the server, along with their name.
// Cert and Key define the paths to the certificate and key to use for
// serving over TLS.
Cert string
Key string
}
Server is a wrapper around the stdlib http.Server. It provides a simple mechanism of adding Routers for routing requests.
func (*Server) AddRouter ¶
AddRouter adds the given router to the server with the given name. If the router already exists, then it will be replaced.
func (*Server) Init ¶
func (s *Server) Init(middleware ...MiddlewareFunc)
Init will initialize the server, and apply the given list of middleware functions to all of the routes added to the server.
type UI ¶
type UI struct {
*Server
// CSRF defines the middleware function to use for protecting form submissions
// from CSRF attacks.
CSRF func(http.Handler) http.Handler
}
UI wraps the Server struct, and provides CSRF middleware for each route.