Documentation ¶
Index ¶
- type HTTPListener
- func (listener *HTTPListener) AddMiddleware(middlewareHandler alice.Constructor) *HTTPListener
- func (listener *HTTPListener) AddRoute(path string, handlerFunc http.HandlerFunc, methods ...string) *HTTPListener
- func (listener *HTTPListener) AddRouteFunction(matcherFunc mux.MatcherFunc, handlerFunc http.HandlerFunc, methods ...string) *HTTPListener
- func (listener *HTTPListener) AddRouteWithMiddleware(path string, handlerFunc http.HandlerFunc, middlewareHandler alice.Constructor, ...) *HTTPListener
- func (listener *HTTPListener) AddStaticRoute(pathPrefix string, directory string) *HTTPListener
- func (listener *HTTPListener) Start() error
- func (listener *HTTPListener) StartTLS(certificateFile, keyFile string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPListener ¶
type HTTPListener struct { Address string Port int Router *mux.Router BaseMiddlewareHandlers alice.Chain }
HTTPListener is a structure which provides an HTTP listener to service requests. This structure offers methods to add routes and middlewares. Typical usage would first call NewHTTPListener(), add routes, then call StartHTTPListener.
func NewHTTPListener ¶
func NewHTTPListener(address string, port int) *HTTPListener
NewHTTPListener creates a new instance of the HTTPListener
func (*HTTPListener) AddMiddleware ¶
func (listener *HTTPListener) AddMiddleware(middlewareHandler alice.Constructor) *HTTPListener
AddMiddleware adds a new middleware handler to the request chain.
func (*HTTPListener) AddRoute ¶
func (listener *HTTPListener) AddRoute(path string, handlerFunc http.HandlerFunc, methods ...string) *HTTPListener
AddRoute adds a HTTP handler route to the HTTP listener.
func (*HTTPListener) AddRouteFunction ¶
func (listener *HTTPListener) AddRouteFunction(matcherFunc mux.MatcherFunc, handlerFunc http.HandlerFunc, methods ...string) *HTTPListener
AddRouteFunction adds an HTTP handler route that is matched by a function call
func (*HTTPListener) AddRouteWithMiddleware ¶
func (listener *HTTPListener) AddRouteWithMiddleware(path string, handlerFunc http.HandlerFunc, middlewareHandler alice.Constructor, methods ...string) *HTTPListener
AddRouteWithMiddleware adds a HTTP handler route that goes through an additional middleware handler, to the HTTP listener. This is particularly useful for setting up routes that require authentication.
func (*HTTPListener) AddStaticRoute ¶
func (listener *HTTPListener) AddStaticRoute(pathPrefix string, directory string) *HTTPListener
AddStaticRoute adds a HTTP handler route for static assets. Note that this does not work with tools that embed assets in your executable. To do that you would need to setup your own static file handler manually.
func (*HTTPListener) Start ¶
func (listener *HTTPListener) Start() error
Start starts the HTTP listener and servicing requests.
func (*HTTPListener) StartTLS ¶
func (listener *HTTPListener) StartTLS(certificateFile, keyFile string) error
StartTLS starts the HTTP listener with SSL and services requests