Documentation ¶
Overview ¶
Package middleware provides HTTP middleware for the application.
Index ¶
- func BasicAuthentication(allowed []string) func(next http.Handler) http.Handler
- func ContentTypeJSON(next http.Handler) http.Handler
- func DevCORS(next http.Handler) http.Handler
- func NewStructuredLogger(logger *logrus.Logger) func(next http.Handler) http.Handler
- func ServeFile(filename string) http.HandlerFunc
- func SinglePageApplication(indexHTML, title, header string) http.HandlerFunc
- type StructuredLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BasicAuthentication ¶
BasicAuthentication is a middleware that authenticates via basic auth, if enabled allowed is a list of user:bcrypt(passwd) strings generated by `htpasswd -nbB user passwd`
func ContentTypeJSON ¶
ContentTypeJSON sets Content-Type (HTTP header) to `application/json`.
func DevCORS ¶
DevCORS allows restricted resources on a web page to be requested from another domain outside the domain from which the first resource was served.
func NewStructuredLogger ¶
NewStructuredLogger creates a middleware with logrus logger.
func ServeFile ¶
func ServeFile(filename string) http.HandlerFunc
ServeFile handles requests for a specific file..
func SinglePageApplication ¶
func SinglePageApplication(indexHTML, title, header string) http.HandlerFunc
SinglePageApplication renders and serves the index.html.
Types ¶
type StructuredLogger ¶
StructuredLogger is a simple, but powerful implementation of a custom structured logger backed on logrus. I encourage users to copy it, adapt it and make it their own. Also take a look at https://github.com/go-chi/httplog for a dedicated pkg based on this work, designed for context-based http routers.
func (*StructuredLogger) NewLogEntry ¶
func (l *StructuredLogger) NewLogEntry(r *http.Request) middleware.LogEntry
NewLogEntry creates a new LogEntry for the request.