trafficpolicy

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScopeAll   = "ALL"
	ScopeTag   = "TAG"
	ScopeProxy = "PROXY"
)

Variables

This section is empty.

Functions

func BatchDelete

func BatchDelete(c *gin.Context, in *BatchDeleteRequest)

BatchDelete 批量删除限速策略

func Create

func Create(c *gin.Context, in *SaveRequest)

func Delete

func Delete(c *gin.Context, in *UuidRequest)

func Disable

func Disable(c *gin.Context, in *UuidRequest)

func Enable

func Enable(c *gin.Context, in *UuidRequest)

func List

func List(c *gin.Context, in *ListRequest)

func RecordTraffic

func RecordTraffic(event TrafficEvent) time.Duration

RecordTraffic 记录真实代理出站流量,并返回当前流量包需要额外等待的时间。

高并发设计说明: 1. 热路径不使用全局锁,策略配置通过 atomic.Value 读取不可变快照; 2. 每条策略的配额、速率窗口、告警冷却时间均使用 atomic 计数; 3. 流量使用量现阶段只放在内存缓存中,不在代理热路径落库; 4. 告警写入通过非阻塞 channel 投递到异步 worker; 5. 没有匹配规则或未触发阈值时直接返回 0,不影响正常代理转发。

func RefreshRuntime

func RefreshRuntime()

RefreshRuntime 同步刷新运行时快照。 用于服务启动、策略 CRUD、状态切换等低频路径;不在每次流量转发中调用。

func RuntimeQuotaUsedMap

func RuntimeQuotaUsedMap() map[string]string

RuntimeQuotaUsedMap 返回当前运行时缓存中的配额使用量快照。

func StartRuntime

func StartRuntime()

StartRuntime 在服务启动时预加载限速配额策略并启动异步 worker。 该函数不在代理转发热路径上,允许同步读取数据库。

func Update

func Update(c *gin.Context, in *SaveRequest)

Types

type BatchDeleteRequest

type BatchDeleteRequest struct {
	Uuids []string `json:"uuids" binding:"required"`
}

type ListRequest

type ListRequest struct {
	Name      string `json:"name"`
	ScopeType string `json:"scope_type"`
	Status    string `json:"status"`
}

type SaveRequest

type SaveRequest struct {
	Uuid                string   `json:"uuid"`
	Name                string   `json:"name" binding:"required"`
	ScopeType           string   `json:"scope_type"`
	ScopeValue          string   `json:"scope_value"`
	OutboundLimit       string   `json:"outbound_limit"`
	MaxConnections      string   `json:"max_connections"`
	PeriodQuota         string   `json:"period_quota"`
	OverLimitActionList []string `json:"over_limit_action_list"`
}

type TrafficEvent

type TrafficEvent struct {
	ProxyUuid         string
	Direction         string
	Bytes             int64
	ActiveConnections int64
}

type UuidRequest

type UuidRequest struct {
	Uuid string `json:"uuid" binding:"required"`
}

Jump to

Keyboard shortcuts

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