shared

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RouteRulesTypeAPIKey = "apikey"
	RouteRulesTypeEntity = "entity"
	RouteRulesTypeGlobal = "global"
)

Variables

This section is empty.

Functions

func BuildBFERateLimitRedisKey added in v0.0.8

func BuildBFERateLimitRedisKey(policyID int64, ruleType string, name string) string

BuildBFERateLimitRedisKey 构造 BFE 实际使用的完整 Redis Key。 控制面在导出时直接下发完整 Key,BFE 侧优先使用该 Key 而不再拼接前缀。

func BuildRateLimitRedisKeys added in v0.0.8

func BuildRateLimitRedisKeys(policyID int64, rules *RateLimitRules) []string

BuildRateLimitRedisKeys 根据限流规则生成 BFE 实际使用的完整 Redis Key 列表。 该函数供 API-Key / Entity 删除或更新时清理 Redis Key 使用。

func DiffRateLimitRedisKeys added in v0.0.8

func DiffRateLimitRedisKeys(policyID int64, oldRules, newRules *RateLimitRules) []string

DiffRateLimitRedisKeys 比较新旧限流策略,返回被删除规则的 Redis Key 列表。 规则按 name 匹配;旧策略中存在但新策略中不存在的 name 视为被删除。

Types

type AiRouteFallbackParam

type AiRouteFallbackParam struct {
	ClusterName *string `json:"cluster_name"`
	Model       *string `json:"model"`
}

func (*AiRouteFallbackParam) UnmarshalJSON

func (f *AiRouteFallbackParam) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts both the new snake_case keys and the legacy camel-case keys for backward compatibility.

type AiRouteRuleParam

type AiRouteRuleParam struct {
	Name      *string                 `json:"name"`
	Cond      *string                 `json:"cond"`
	Targets   []*AiRouteTargetParam   `json:"targets"`
	Fallbacks []*AiRouteFallbackParam `json:"fallbacks"`
}

func (*AiRouteRuleParam) UnmarshalJSON

func (r *AiRouteRuleParam) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts both the new snake_case keys and the legacy camel-case keys for backward compatibility.

type AiRouteTargetParam

type AiRouteTargetParam struct {
	ClusterName *string `json:"cluster_name"`
	Model       *string `json:"model"`
	Weight      *int    `json:"weight"`
}

func (*AiRouteTargetParam) UnmarshalJSON

func (t *AiRouteTargetParam) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts both the new snake_case keys and the legacy camel-case keys for backward compatibility with existing database records and old clients. Serialization continues to emit only the new keys.

type BalanceSummary

type BalanceSummary struct {
	Used      *float64 `json:"used"`
	Remaining *float64 `json:"remaining"`
}

type EntityFilter

type EntityFilter struct {
	EntityID *string `form:"id"`
	Name     *string `form:"name"`
	Type     *string `form:"type"`
	ParentID *string `form:"parent_id"`
	Page     *int    `form:"page"`
	PageSize *int    `form:"page_size"`
}

type EntityStorager

type EntityStorager interface {
	FetchEntity(ctx context.Context, filter *EntityFilter) (*EntitySummary, error)
}

type EntitySummary

type EntitySummary struct {
	ID   *string `json:"id"`
	Name *string `json:"name"`
	Type *string `json:"type"`
}

type QuotaPlanParam

type QuotaPlanParam struct {
	Unlimited             *bool           `json:"unlimited"`
	PassWhenNoEnoughQuota *bool           `json:"pass_when_no_enough_quota"`
	Quota                 *float64        `json:"quota"`
	Unit                  *string         `json:"unit"`
	ResetPeriod           *string         `json:"reset_period"`
	LastResetAt           *time.Time      `json:"last_reset_at,omitempty"`
	Balance               *BalanceSummary `json:"balance,omitempty"`
}

type QuotaPlanStorager

type QuotaPlanStorager interface {
	CreateQuotaPlan(ctx context.Context, param *QuotaPlanParam) (int64, error)
	UpdateQuotaPlan(ctx context.Context, id int64, param *QuotaPlanParam) (int64, error)
	DeleteQuotaPlan(ctx context.Context, id int64) error
	FetchQuotaPlan(ctx context.Context, id int64) (*QuotaPlanParam, error)
}

type RPMConfig

type RPMConfig struct {
	Name          string `json:"name"`
	Model         string `json:"model"`
	WindowMinutes int    `json:"window_minutes"`
	MaxRequests   int    `json:"max_requests"`
}

type RateLimitPolicyParam

type RateLimitPolicyParam struct {
	Enabled *bool           `json:"enabled"`
	Rules   *RateLimitRules `json:"rules"`
}

type RateLimitPolicyStorager

type RateLimitPolicyStorager interface {
	CreateRateLimitPolicy(ctx context.Context, param *RateLimitPolicyParam) (int64, error)
	UpdateRateLimitPolicy(ctx context.Context, id int64, param *RateLimitPolicyParam) (int64, error)
	DeleteRateLimitPolicy(ctx context.Context, id int64) error
	FetchRateLimitPolicy(ctx context.Context, id int64) (*RateLimitPolicyParam, error)
}

type RateLimitRules

type RateLimitRules struct {
	TpmConfigs     []TPMConfig `json:"tpm"`
	RpmConfigs     []RPMConfig `json:"rpm"`
	MaxConcurrency *int        `json:"max_concurrency"`
}

type RouteRulesFilter

type RouteRulesFilter struct {
	Type      *string `form:"type"`
	Owner     *string `form:"owner"`
	Enabled   *bool   `form:"enabled"`
	Page      *int    `form:"page"`
	PageSize  *int    `form:"page_size"`
	SortBy    *string `form:"sort_by"`
	SortOrder *string `form:"sort_order"`
}

RouteRulesFilter defines filters for querying route rules

type RouteRulesParam

type RouteRulesParam struct {
	ID      *int64              `json:"-"`
	Enabled *bool               `json:"enabled"`
	Rules   []*AiRouteRuleParam `json:"rules"`
}

type RouteRulesStorager

type RouteRulesStorager interface {
	CreateRouteRules(ctx context.Context, ruleType string, owner *string, param *RouteRulesParam) (int64, error)
	FetchRouteRules(ctx context.Context, ruleType string, owner *string) (*RouteRulesParam, error)
	FetchRouteRulesList(ctx context.Context, filter *RouteRulesFilter) ([]*RouteTableParam, int64, error)
	UpdateRouteRules(ctx context.Context, id int64, param *RouteRulesParam) (int64, error)
	DeleteRouteRules(ctx context.Context, id int64) error
	FetchRouteRulesByID(ctx context.Context, id int64) (*RouteRulesParam, error)
	// FetchAllRouteRules returns all route rules without pagination.
	// Used by reference checkers that must scan every rule table.
	FetchAllRouteRules(ctx context.Context) ([]*RouteRulesParam, error)
}

RouteRulesStorager defines storage operations for route rules

type RouteTableParam

type RouteTableParam struct {
	ID      *int64 `json:"id,omitempty"`
	Type    string `json:"type"`
	Owner   string `json:"owner"`
	Enabled bool   `json:"enabled"`
}

type TPMConfig

type TPMConfig struct {
	Name          string `json:"name"`
	Model         string `json:"model"`
	WindowMinutes int    `json:"window_minutes"`
	MaxTokens     int    `json:"max_tokens"`
	StepMinutes   int    `json:"step_minutes"`
}

Jump to

Keyboard shortcuts

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