middleware

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2025 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RouteManager      *routeParamsManager
	CommonMiddlewares = []gin.HandlerFunc{}
	AuthMiddlewares   = []gin.HandlerFunc{}
)

Functions

func AddSpanEvent

func AddSpanEvent(c *gin.Context, name string, attrs ...attribute.KeyValue)

AddSpanEvent adds an event to the current span

func AddSpanTags

func AddSpanTags(c *gin.Context, tags map[string]any)

AddSpanTags adds custom tags to the current span

func Authz

func Authz() gin.HandlerFunc

Authz 中间件开启时必须也开启 JwtAuth 中间件, 并且位于 JwtAuth 之后. 要不然 username 会为空则则 isAllow 总是为 false.

func BaseAuth

func BaseAuth() gin.HandlerFunc

func CircuitBreaker

func CircuitBreaker() gin.HandlerFunc

func Cors

func Cors() gin.HandlerFunc

func GetSpanFromContext

func GetSpanFromContext(c *gin.Context) trace.Span

GetSpanFromContext retrieves the OpenTelemetry span from Gin context

func Gzip

func Gzip() gin.HandlerFunc

func Init

func Init() (err error)

func JwtAuth

func JwtAuth() gin.HandlerFunc

JwtAuth 效果如下: 1.重复登录之后,会刷新 accessToken, refreshToken, 之后老的 accessToken 是失效 2.换浏览器、换操作系统都需要重新登录,重新登录之后会挤掉其他设备、浏览器的登录

func Logger

func Logger(filename ...string) gin.HandlerFunc

func NewRouteParamsManager

func NewRouteParamsManager() *routeParamsManager

func RateLimiter

func RateLimiter() gin.HandlerFunc

func RecordError

func RecordError(c *gin.Context, err error)

RecordError records an error in the current span

func Recovery

func Recovery(filename ...string) gin.HandlerFunc

func RecoveryWithTracing

func RecoveryWithTracing(logger *zap.Logger, stack bool) gin.HandlerFunc

RecoveryWithTracing returns a gin.HandlerFunc (middleware) that recovers from any panics and logs requests using uber-go/zap. All errors are logged using zap.Error(). stack means whether output the stack info. The stack info is easy to find where the error occurs but the stack info is too large.

func Register

func Register(middlewares ...gin.HandlerFunc)

Register adds global middlewares that apply to all routes with automatic tracing wrapper. Call this if a middlewares should run for every requests. All middlewares registered through this function will be automatically wrapped for performance tracking. The middleware name is automatically extracted from the function name using reflection.

func RegisterAuth

func RegisterAuth(middlewares ...gin.HandlerFunc)

RegisterAuth adds authentication/authorization middlewares with automatic tracing wrapper, which are only appied to routes that requests authentication/authorization. Call this if a route must be protected by auth logic. All middlewares registered through this function will be automatically wrapped for performance tracking. The middleware name is automatically extracted from the function name using reflection.

func RouteParams

func RouteParams() gin.HandlerFunc

RouteParams is a middleware to get route parameters

func TraceID

func TraceID() gin.HandlerFunc

func Tracing

func Tracing() gin.HandlerFunc

Tracing returns a middleware that handles both trace ID generation and OpenTelemetry tracing This middleware combines the functionality of TraceID() and Tracing() middlewares

Types

This section is empty.

Jump to

Keyboard shortcuts

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