middleware

package
v0.0.0-...-48495d3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

middleware package contains useful middleware to wrap over routes to provide useful functionality.

Index

Constants

This section is empty.

Variables

View Source
var (
	Debug = _debug{}
	Info  = _info{}
	Warn  = _warn{}
	Error = _error{}
)

Global logging levels for the Logging middleware.

View Source
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) Authorise

func (a *AuthMiddleware) Authorise(r *http.Request) 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.

type Wrapper

type Wrapper func(next http.Handler) http.Handler

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL