middleware

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: May 22, 2022 License: MIT Imports: 5 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(),
}

Middlewares store default middlewares.

Functions

func Cors

func Cors() gin.HandlerFunc

Cors returns a middleware that adds cors headers.

func NoCache

func NoCache(c *gin.Context)

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

func Options

func Options(c *gin.Context)

Options is a middleware function 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(c *gin.Context)

Secure is a middleware function 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 is used to do authentication.

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