middleware

package
v0.0.0-...-eb6e4a7 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 18 Imported by: 0

README

Gin 自带的中间件有很多种,可以在 https://github.com/gin-gonic/contrib 找到。

下面是一些常用的中间件

  • RestGate:REST API 端点的安全身份验证
  • gin-jwt:用于 Gin 框架的 JWT 中间件
  • gin-sessions:基于 MongoDB 和 MySQL 的会话中间件
  • gin-location:用于公开服务器主机名和方案的中间件
  • gin-nice-recovery:异常错误恢复中间件,让您构建更好的用户体验
  • gin-limit:限制同时请求,可以帮助解决高流量负载
  • gin-oauth2:用于处理 OAuth2
  • gin-template:简单易用的 Gin 框架 HTML/模板
  • gin-redis-ip-limiter:基于 IP 地址的请求限制器
  • gin-access-limit:通过指定允许的源 CIDR 表示法来访问控制中间件
  • gin-session:Gin 的会话中间件
  • gin-stats:轻量级且有用的请求指标中间件
  • gin-session-middleware:一个高效,安全且易于使用的 Go 会话库
  • ginception:漂亮的异常页面
  • gin-inspector:用于调查 HTTP 请求的 Gin 中间件

Reference

Documentation

Index

Constants

View Source
const (
	// HeaderSignToken 签名验证 Authorization,Header 中传递的参数
	HeaderSignToken = "Auth"

	// HeaderSignTokenDate 签名验证 Date,Header 中传递的参数
	HeaderSignTokenDate = "Auth-Date"

	// HeaderSignTokenTimeout 签名有效期为 1 分钟
	HeaderSignTokenTimeout = time.Minute
)

Variables

This section is empty.

Functions

func AccessLog

func AccessLog() gin.HandlerFunc

AccessLog record access log.

func Cors

func Cors(c *gin.Context)

Cors 处理跨域请求,支持options访问

func HandleErrors

func HandleErrors(c *gin.Context)

HandleErrors 异常捕获处理

func IPLimiter

func IPLimiter(limit int, expire time.Duration) gin.HandlerFunc

IPLimiter ip限制

func Init

func Init(namespace string)

Init registers the prometheus metrics

func Logging

func Logging() gin.HandlerFunc

Logging is a middleware function that logs the request.

func MaxLimiter

func MaxLimiter(n int) gin.HandlerFunc

MaxLimiter 限制同时最大请求数

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 Prom

func Prom(opts ...PromOpt) gin.HandlerFunc

Prom returns a gin.HandlerFunc for exporting some Web metrics

func PromHandler

func PromHandler(handler http.Handler) gin.HandlerFunc

PromHandler wrappers the standard http.Handler to gin.HandlerFunc

func Secure

func Secure(c *gin.Context)

Secure is a middleware function that appends security and resource access headers.

func Timeout

func Timeout(t time.Duration) gin.HandlerFunc

Timeout 超时中间件

func VerifySign

func VerifySign(secretKey string, opts ...VerifyOpt) gin.HandlerFunc

VerifySign 验证签名

Types

type PromOpt

type PromOpt func(opts *PromOpts)

PromOpt 设置 PromOpts 选项

func WithEndpointLabel

func WithEndpointLabel(fn func(c *gin.Context) string) PromOpt

WithEndpointLabel 设置 EndpointLabel

func WithNamespace

func WithNamespace(namespace string) PromOpt

WithNamespace 设置 Namespace

type PromOpts

type PromOpts struct {
	Namespace            string
	ExcludeRegexStatus   string
	ExcludeRegexEndpoint string
	ExcludeRegexMethod   string
	EndpointLabelFn      func(c *gin.Context) string
}

PromOpts represents the Prometheus middleware Options. It is used for filtering labels by regex.

type VerifyOpt

type VerifyOpt func(opts *VerifyOpts)

func WithExcept

func WithExcept(uris []string) VerifyOpt

func WithTimeout

func WithTimeout(timeout time.Duration) VerifyOpt

type VerifyOpts

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

Jump to

Keyboard shortcuts

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