public

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ValidatorKey        = "ValidatorKey"
	TranslatorKey       = "TranslatorKey"
	AdminSessionInfoKey = "AdminSessionInfoKey"

	LoadTypeHTTP = 0
	LoadTypeTCP  = 1
	LoadTypeGRPC = 2

	RuleTypePrefixURL = 0
	RuleTypeDomin     = 1

	RedisFlowDayKey  = "flow_day_count"
	RedisFlowHourKey = "flow_hour_count"

	FlowTotal              = "flow_total"
	FlowCountServicePrefix = "flow_service_"
	FlowCountAppPrefix     = "flow_app_"
	FlowServicePrefix      = "flow_service_"
	FlowAppPrefix          = "flow_app_"

	JwtSignKey = "my_sign_key"
	JwtExpires = 60 * 60
)

Variables

View Source
var (
	LoadTypeMap = map[int]string{
		LoadTypeHTTP: "HTTP",
		LoadTypeTCP:  "TCP",
		LoadTypeGRPC: "GRPC",
	}
)

Functions

func ComLogNotice

func ComLogNotice(c *gin.Context, dltag string, m map[string]interface{})

普通日志

func ComLogWarning

func ComLogWarning(c *gin.Context, dltag string, m map[string]interface{})

错误日志

func ContextError

func ContextError(c context.Context, dltag string, m map[string]interface{})

错误日志

func ContextNotice

func ContextNotice(c context.Context, dltag string, m map[string]interface{})

普通日志

func ContextWarning

func ContextWarning(c context.Context, dltag string, m map[string]interface{})

错误日志

func DefaultGetValidParams

func DefaultGetValidParams(c *gin.Context, params interface{}) error

func GenSaltPassword

func GenSaltPassword(salt, password string) string

func GetGinTraceContext

func GetGinTraceContext(c *gin.Context) *lib.TraceContext

从gin的Context中获取数据

func GetTraceContext

func GetTraceContext(c context.Context) *lib.TraceContext

从Context中获取数据

func GetTranslation

func GetTranslation(c *gin.Context) (ut.Translator, error)

func GetValidator

func GetValidator(c *gin.Context) (*validator.Validate, error)

func InStringSlice

func InStringSlice(slice []string, str string) bool

func JwtDecode

func JwtDecode(tokenString string) (*jwt.StandardClaims, error)

func JwtEncode

func JwtEncode(claims jwt.StandardClaims) (string, error)

func MD5

func MD5(s string) string

MD5 md5加密

func Obj2Json

func Obj2Json(s interface{}) string

func RedisConfDo

func RedisConfDo(commandName string, args ...interface{}) (interface{}, error)

func RedisConfPipline

func RedisConfPipline(pip ...func(c redis.Conn)) error

Types

type FlowCounter

type FlowCounter struct {
	RedisFlowCountMap   map[string]*RedisFlowCountService
	RedisFlowCountSlice []*RedisFlowCountService
	Locker              sync.RWMutex
}
var FlowCounterHandler *FlowCounter

func NewFlowCounter

func NewFlowCounter() *FlowCounter

func (*FlowCounter) GetCounter

func (counter *FlowCounter) GetCounter(serviceName string) (*RedisFlowCountService, error)

type FlowLimiter

type FlowLimiter struct {
	FlowLimiertMap   map[string]*FlowLimiterItem
	FlowLimiterSlice []*FlowLimiterItem
	Locker           sync.RWMutex
}
var FlowLimiterHandler *FlowLimiter

func NewFlowLimiter

func NewFlowLimiter() *FlowLimiter

func (*FlowLimiter) GetLimiter

func (limiter *FlowLimiter) GetLimiter(serviceName string, qps float64) (*rate.Limiter, error)

type FlowLimiterItem

type FlowLimiterItem struct {
	ServiceName string
	Limiter     *rate.Limiter
	Qps         float64
}

type RedisFlowCountService

type RedisFlowCountService struct {
	AppID       string
	Interval    time.Duration
	QPS         int64
	Unix        int64
	TickerCount int64
	TotalCount  int64
}

func NewRedisFlowCountService

func NewRedisFlowCountService(appID string, interval time.Duration) *RedisFlowCountService

func (*RedisFlowCountService) GetDayData

func (o *RedisFlowCountService) GetDayData(t time.Time) (int64, error)

func (*RedisFlowCountService) GetDayKey

func (o *RedisFlowCountService) GetDayKey(t time.Time) string

func (*RedisFlowCountService) GetHourData

func (o *RedisFlowCountService) GetHourData(t time.Time) (int64, error)

func (*RedisFlowCountService) GetHourKey

func (o *RedisFlowCountService) GetHourKey(t time.Time) string

func (*RedisFlowCountService) Increase

func (o *RedisFlowCountService) Increase()

Increase 原子增加

Jump to

Keyboard shortcuts

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