Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChainMiddlewares ¶
func ChainMiddlewares(lastHandler nethttp.Handler, middlewares ...Middleware) nethttp.Handler
ChainMiddlewares returns a net/http.Handler that chains a list of Middlewares where the last middleware is a simple wrapper around the given lastHandler.
Types ¶
type HandlerFactory ¶
HandlerFactory is a function used to create the net/http.Handler for the main server.
type Middleware ¶
type Middleware func(nethttp.ResponseWriter, *nethttp.Request, MiddlewareWrapper) error
Middleware represents an HTTP handler function that receives the next Middleware (through its MiddlewareWrapper) and is allowed to control the execution flow calling this next Middleware or not.
type MiddlewareWrapper ¶
type MiddlewareWrapper func(nethttp.ResponseWriter, *nethttp.Request) error
MiddlewareWrapper wraps around a Middleware.
type Server ¶
type Server struct { // HTTPEndpoint is the endpoint to serve the main server. HTTPEndpoint string // HTTPRandomPort controls if a random port should be chosen to expose the HTTPEndpoint; if // true, a random port p is chosen and the leftmost occurrence of POSIX regex ($)|(:[0-9]*$) // in HTTPEndpoint is replaced by ":p". HTTPRandomPort bool // HTTPSEndpoint is the endpoint to serve the main server over TLS. HTTPSEndpoint string // HTTPSRandomPort controls if a random port should be chosen to expose the HTTPSEndpoint; if // true, a random port p is chosen and the leftmost occurrence of POSIX regex ($)|(:[0-9]*$) // in HTTPSEndpoint is replaced by ":p". HTTPSRandomPort bool // CertFile contains the TLS certificate to pass to net/http.Server.ServeTLS(). CertFile string // KeyFile contains the TLS key to pass to net/http.Server.ServeTLS(). KeyFile string // HandlerFactory is used to create the net/http.Handler that serves both http://HTTPEndpoint // and https://HTTPSEndpoint if they are set to be created. HandlerFactory HandlerFactory // InternalEndpoint is the endpoint to serve helper routes like GET /health. InternalEndpoint string // HealthHandler serves GET http://InternalEndpoint/health. HealthHandler nethttp.Handler // RegisterInternalHandlers is a hook to register custom handlers at http://InternalEndpoint, // except GET /health which is already required. RegisterInternalHandlers func(*nethttp.ServeMux) // Logger is used to emit logs when the starts and stops. Logger logrus.FieldLogger // contains filtered or unexported fields }
Server exposes HTTPEndpoint with the net/http.Handler returned by HandlerFactory, HTTPSEndpoint with the same net/http.Handler and an InternalEndpoint routing GET /health to HealthHandler; the response of HealthHandler is used by WaitForReady() to determine if the server is ready. If HTTPEndpoint is empty, the endpoint is not exposed unless HTTPRandomPort is set to true (the same is valid for HTTPSEndpoint and HTTPSRandomPort). If InternalEndpoint is empty, a random port p is chosen and InternalEndpoint is set to ":p".
func NewServer ¶
NewServer creates or only initializes (if server is nil) the runtime of a server with the default runtime if runtime is nil, and also initializes other fields that compose internal state.
func (*Server) GracefulShutdown ¶
func (s *Server) GracefulShutdown()
GracefulShutdown notifies the server to stop.