mw

package
v1.2.0-awscostswork.2 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

package mw is the middleware handler

Provides the Middleware function that allows chaining of http requests from a server. This allows for logging, enforcing auth, output headers etc in a neat fashion

Includes common middleware:

  • Logging
  • SecurityHeaders

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logging

func Logging(w http.ResponseWriter, r *http.Request)

Logging uses the default structured log instance to output some information about the incoming request

func Middleware

func Middleware(handlerFunc http.HandlerFunc, middleware ...MiddlewareFunc) http.HandlerFunc

Middleware facilitates creation of middleware chains, with them being called in sequence. Normally configuerd by the IApi Register func, but can be called directly if required.

mux.HandleFunc("/user/{id}/{$}", Middleware(GetUserById, Logging, SecurityHeaders))

Calls internal function `wrap`, which reduces some of the boiler plate required with chaining, so the handler should be setup as a normal handler func

func SecurityHeaders

func SecurityHeaders(w http.ResponseWriter, r *http.Request)

SecurityHeaders attaches standard headers to the response

Types

type MiddlewareFunc

type MiddlewareFunc func(w http.ResponseWriter, r *http.Request)

MiddlewareFunc type matching for chaining middleware

type MiddlewareHandlerFunc

type MiddlewareHandlerFunc func(http.HandlerFunc) http.HandlerFunc

MiddlewareHandler is alias for http.HandlerFunc to allow chaining

Jump to

Keyboard shortcuts

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