middleware

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package middleware defines multiple gin middlewares.

Index

Constants

View Source
const UsernameKey = "username"

UsernameKey defines the key in gin context which represents the owner of the secret.

View Source
const XRequestIDKey = "X-Request-ID"

XRequestIDKey defines X-Request-ID key string.

Variables

View Source
var Middlewares = map[string]gin.HandlerFunc{
	"recovery":  gin.Recovery(),
	"secure":    Secure(),
	"options":   Options(),
	"nocache":   NoCache(),
	"cors":      Cors(),
	"requestid": RequestID(),
	"context":   Context(),
	"logger":    Logger(),
}

Middlewares store default middlewares.

Functions

func Context added in v0.1.9

func Context() gin.HandlerFunc

Context returns a middleware that injects requestID and username to gin.Context.

func Cors

func Cors() gin.HandlerFunc

Cors returns a middleware that adds cors headers.

func Logger added in v0.1.9

func Logger() gin.HandlerFunc

Logger returns a middleware that adds requestID and username to the loggin context.

func NoCache

func NoCache() gin.HandlerFunc

NoCache returns a middleware that appends headers to prevent the client from caching the HTTP response.

func Options

func Options() gin.HandlerFunc

Options returns a middleware that appends headers for OPTIONS requests.

func RequestID

func RequestID() gin.HandlerFunc

RequestID returns a middleware that injects a 'X-Request-ID' into the context and request/response header of each request.

func Secure

func Secure() gin.HandlerFunc

Secure returns a middleware that appends security and resource access headers.

Types

type AuthOperator

type AuthOperator struct {
	// contains filtered or unexported fields
}

AuthOperator is used to switch between different auth strategy.

func (*AuthOperator) AuthFunc

func (operator *AuthOperator) AuthFunc() gin.HandlerFunc

AuthFunc executes authentication.

func (*AuthOperator) SetStrategy

func (operator *AuthOperator) SetStrategy(strategy AuthStrategy)

SetStrategy sets the strategy to operator.

type AuthStrategy

type AuthStrategy interface {
	AuthFunc() gin.HandlerFunc
}

AuthStrategy defines the behavior of a authenticator.

Directories

Path Synopsis
Package auth defines authentication strategy like Basic, Bearer.
Package auth defines authentication strategy like Basic, Bearer.

Jump to

Keyboard shortcuts

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