middle

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CustomerRequestsTotal = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "custom_http_requests_total",
			Help: "Total number of HTTP requests.",
		},
		[]string{"path", "method", "status"},
	)
	ThrottleCounter = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "throttle_counter_total",
			Help: "Total number of requests that passed the throttle.",
		},
		[]string{"resource", "status"},
	)
)

全局 Prometheus 指标

View Source
var Auth *auth

定义全局变量

Functions

func CacheMiddle

func CacheMiddle(duration time.Duration, key ...string) gin.HandlerFunc

duration:缓存时长,key:可选参数缓存key

func GetRateLimiter

func GetRateLimiter(resourceName string) (*rate.Limiter, bool)

GetRateLimiter 获取限流器,确保每个资源名对应的限流器是持久化的

func InitAuth

func InitAuth(service rbac.IRBACService)

初始化函数

func LogInfoMiddle

func LogInfoMiddle() gin.HandlerFunc

日志中间件

func PanicMiddle

func PanicMiddle() gin.HandlerFunc

用于捕获并记录panic的中间件

func PrometheusMiddle

func PrometheusMiddle() gin.HandlerFunc

PrometheusMiddleware 记录常规的 HTTP 请求统计数据

func RegisterPrometheus

func RegisterPrometheus()

在 Gin 路由中注册 Prometheus 处理程序

func ThrottleMiddle

func ThrottleMiddle(resourceName string) gin.HandlerFunc

ThrottleMiddle 限流中间件

Types

type CustomClaims

type CustomClaims struct {
	Id      int64
	Account string
	jwt.StandardClaims
}

type ThrottleEntity

type ThrottleEntity struct {
	RateLimit int `gorm:"column:rate_limit" json:"RateLimit" form:"RateLimit" comment:"RateLimit"` // 每秒令牌生成数
	Burst     int `gorm:"column:burst" json:"Burst" form:"Burst" comment:"Burst"`                  // 突发容量
	WaitTime  int `gorm:"column:wait_time" json:"WaitTime" form:"WaitTime" comment:"WaitTime"`     // 最大排队等待时间
}

Directories

Path Synopsis
model.go
model.go

Jump to

Keyboard shortcuts

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