Documentation ¶
Index ¶
Constants ¶
View Source
const LogIDKey = "X-Log-Id"
Variables ¶
This section is empty.
Functions ¶
func NewCorsMW ¶
func NewCorsMW(config *CORSConfig) gin.HandlerFunc
Types ¶
type CORSConfig ¶
type GinConfig ¶
type GinConfig struct { Addr string `yaml:"Addr" json:"Addr"` Mode string `yaml:"Mode" json:"Mode"` EnableBaseMw bool `yaml:"EnableBaseMw" json:"EnableBaseMw"` EnablePprof bool `yaml:"EnablePprof" json:"EnablePprof"` ProfilePath string `yaml:"ProfilePath" json:"ProfilePath"` CORS *CORSConfig `yaml:"CORS" json:"CORS"` RateLimit *RateLimitConfig `yaml:"RateLimit" json:"RateLimit"` GracefulExitSec int64 `yaml:"GracefulExitSec" json:"GracefulExitSec"` }
type GinHttpServer ¶
type GinHttpServer struct {
// contains filtered or unexported fields
}
func NewGinHttpServer ¶
func NewGinHttpServer(config *GinConfig) *GinHttpServer
func (*GinHttpServer) GetConfig ¶
func (self *GinHttpServer) GetConfig() GinConfig
func (*GinHttpServer) GetEngine ¶
func (self *GinHttpServer) GetEngine() *gin.Engine
func (*GinHttpServer) Init ¶
func (self *GinHttpServer) Init() *GinHttpServer
type GinRateLimiter ¶
type GinRateLimiter struct {
RuleItems []*RuleItem
}
func NewGinRateLimiter ¶
func NewGinRateLimiter(config *RateLimitConfig) *GinRateLimiter
func (*GinRateLimiter) Check ¶
func (l *GinRateLimiter) Check(c context.Context, path, userID, fromIP string) bool
func (*GinRateLimiter) RateLimitMW ¶
func (l *GinRateLimiter) RateLimitMW() gin.HandlerFunc
func (*GinRateLimiter) Reload ¶
func (l *GinRateLimiter) Reload(config *RateLimitConfig)
type RateLimitConfig ¶
type RateLimitConfig struct {
Rules []*RateLimitRule `yaml:"Rules" json:"Rules"`
}
type RateLimitRule ¶
type RateLimitRule struct { // Mode 限流模式 Mode RateLimitRuleMode `yaml:"Mode" json:"Mode"` // MatchPathPrefix 匹配路径前缀 MatchPathPrefix string `yaml:"MatchPathPrefix" json:"MatchPathPrefix"` // PerUserLimit 用户限流值 PerUserLimit *int `yaml:"PerUserLimit" json:"PerUserLimit"` // PerIPLimit IP 限流值 PerIPLimit *int `yaml:"PerIPLimit" json:"PerIPLimit"` // GlobalLimit 全局限流值 GlobalLimit *int `yaml:"GlobalLimit" json:"GlobalLimit"` // CycleSecond 限流周期,单位秒 CycleSecond int `yaml:"CycleSecond" json:"CycleSecond"` // BreakIfMatch 为 true 时,匹配到该规则后不再继续匹配后续规则 BreakIfMatch bool `yaml:"BreakIfMatch" json:"BreakIfMatch"` }
type RateLimitRuleMode ¶
type RateLimitRuleMode string
const ( ModeTokenBucket RateLimitRuleMode = "token_bucket" ModeLeakyBucket RateLimitRuleMode = "leak_bucket" )
Click to show internal directories.
Click to hide internal directories.