gin_server

package
v0.0.0-...-785e849 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const LogIDKey = "X-Log-Id"

Variables

This section is empty.

Functions

func BizDataMw

func BizDataMw(c *gin.Context)

func NewCorsMW

func NewCorsMW(config *CORSConfig) gin.HandlerFunc

func StatMW

func StatMW(c *gin.Context)

Types

type CORSConfig

type CORSConfig struct {
	Enable       bool     `yaml:"Enable" json:"Enable"`
	AllowOrigins []string `yaml:"AllowOrigins" json:"AllowOrigins"`
}

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

func (*GinHttpServer) Run

func (self *GinHttpServer) Run(ctx context.Context) error

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"
)

type RuleItem

type RuleItem struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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