Documentation
¶
Overview ¶
middleware package contains useful middleware to wrap over routes to provide useful functionality.
Index ¶
- Variables
- type AuthMiddleware
- type LoggerLevel
- type LoggingMiddleware
- func (l *LoggingMiddleware) HeaderPrepared() bool
- func (l *LoggingMiddleware) Log(level LoggerLevel, message string, attrs ...any)
- func (l *LoggingMiddleware) PrepareHeader(statusCode int)
- func (l *LoggingMiddleware) Status() int
- func (l *LoggingMiddleware) WriteHeader(statusCode int)
- func (l *LoggingMiddleware) WritePreparedHeader()
- type Wrapper
Constants ¶
This section is empty.
Variables ¶
var ( Debug = _debug{} Info = _info{} Warn = _warn{} Error = _error{} )
Global logging levels for the Logging middleware.
var Handlers = &middlewares{
Logger: loggerWrapper,
Authorisation: authorisationWrapper,
}
Handlers is a package level variable containing middleware wrapper functions.
Functions ¶
This section is empty.
Types ¶
type AuthMiddleware ¶
type AuthMiddleware struct { *LoggingMiddleware // contains filtered or unexported fields }
AuthMiddleware is an extension over LoggingMiddleware (and by extension http.ResponseWriter) to handle proper authorisation of a child http.Handler.
For AuthMiddleware to work, a parent http.Handler must have been wrapped by the Logger wrapper method as it is required for this middleware.
func (AuthMiddleware) Authed ¶
func (a AuthMiddleware) Authed() bool
func (AuthMiddleware) Details ¶
func (a AuthMiddleware) Details() (*uuid.UUID, bool)
Details returns a pair, a nullable uuid.UUID and bool depending on whether or not the user is authorised with the uuid.UUID representing the authorised token previously checked.
func (AuthMiddleware) Log ¶
func (a AuthMiddleware) Log(level LoggerLevel, message string, attrs ...any)
Wrapper over LoggingMiddleware.Log to standardise the prefix.
type LoggerLevel ¶
type LoggerLevel interface {
// contains filtered or unexported methods
}
type LoggingMiddleware ¶
type LoggingMiddleware struct { http.ResponseWriter // contains filtered or unexported fields }
LoggingMiddleware is an extension over http.ResponseWriter to standardise logging throughout the application. If the http.Handler has been wrapped in the Logger wrapper function, then all children will be able to cast their http.ResponseWriter types to LoggingMiddleware and use LoggingMiddleware.Log directly. Additionally, middleware's that require LoggingMiddleware can implement a Log method to modify the default behaviour. For example, see AuthMiddleware.Log.
func (*LoggingMiddleware) HeaderPrepared ¶
func (l *LoggingMiddleware) HeaderPrepared() bool
HeaderPrepared returns whether or not the header has been prepared.
func (*LoggingMiddleware) Log ¶
func (l *LoggingMiddleware) Log(level LoggerLevel, message string, attrs ...any)
func (*LoggingMiddleware) PrepareHeader ¶
func (l *LoggingMiddleware) PrepareHeader(statusCode int)
PrepareHeader sets the status code of the request without calling LoggingMiddleware.WriteHeader.
func (*LoggingMiddleware) Status ¶
func (l *LoggingMiddleware) Status() int
Status returns the current status of the request.
func (*LoggingMiddleware) WriteHeader ¶
func (l *LoggingMiddleware) WriteHeader(statusCode int)
WriteHeader writes the given statusCode to the status header for the request. Subsequent calls to LoggingMiddleware.WritePreparedHeader or LoggingMiddleware.WriteHeader are superflous and will be ignored.
func (*LoggingMiddleware) WritePreparedHeader ¶
func (l *LoggingMiddleware) WritePreparedHeader()
WritePreparedHeader writes the previously prepared w.status to the status header for the request. Subsequent calls to LoggingMiddleware.WritePreparedHeader or LoggingMiddleware.WriteHeader are superflous and will be ignored.