middle

package
v1.1.16 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: GPL-3.0 Imports: 12 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 指标

Functions

func ACLMiddle

func ACLMiddle() gin.HandlerFunc

AccessControlMiddleware 创建访问控制中间件

func AcsMiddle

func AcsMiddle() gin.HandlerFunc

func PrometheusMiddle

func PrometheusMiddle() gin.HandlerFunc

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

func RegisterPrometheus

func RegisterPrometheus(port int)

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

func ThrottleMiddle

func ThrottleMiddle(resourceName string) gin.HandlerFunc

Types

type AccessEntity

type AccessEntity struct {
	Path   string
	UserId string
	Count  int
}

type AccessctlEntity

type AccessctlEntity struct {
	Path        string
	Access      int
	Ips         string
	Description string
	Status      int
}

type ThrottleEntity

type ThrottleEntity struct {
	Limiter   *rate.Limiter
	UserId    string //用户Id
	RateLimit int    // 每秒令牌生成数
	Burst     int    // 突发容量
	WaitTime  int    // 最大排队等待时间
	CustomSet bool   // 自定义配置
}

func GetThrottleEntity

func GetThrottleEntity(resourceName string, useDefault bool) *ThrottleEntity

GetThrottleEntity 获取限流实体,确保每个资源名对应的限流实体是持久化的

Jump to

Keyboard shortcuts

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