Documentation ¶
Index ¶
- Variables
- func CurrentMicrosecond() int64
- func CurrentMillisecond() int64
- func CurrentNanosecond() int64
- func IsSuccess(code uint32) bool
- func IsSysErr(code uint32) bool
- func IsUserErr(code uint32) bool
- func ParseClientAddr(ctx context.Context) string
- func ParseClientIP(ctx context.Context) string
- func ParseRequestID(ctx context.Context) string
- func ParseUserAgent(ctx context.Context) string
- func TimestampMsToUtcIso8601(timestamp int64) string
- func WithClientAddr(ctx context.Context, addr string) context.Context
- func WithClientIP(ctx context.Context, ip string) context.Context
- func WithRequestID(ctx context.Context, requestID string) context.Context
- func WithStructClientIP(ctx context.Context, ip *IPAddress) context.Context
- func WithUserAgent(ctx context.Context, agent string) context.Context
- func WrapperBool(value bool) *wrappers.BoolValue
- func WrapperInt64(value int64) *wrappers.Int64Value
- func WrapperString(value string) *wrappers.StringValue
- func WrapperUint32(value uint32) *wrappers.UInt32Value
- func ZapClientAddr(ctx context.Context) zap.Field
- func ZapCode(code uint32) zap.Field
- func ZapLimitKey(key string) zap.Field
- func ZapLimitService(service string, namespace string) zap.Field
- func ZapMethod(method string) zap.Field
- func ZapMsgId(msgId int64) zap.Field
- func ZapRequestID(ctx context.Context) zap.Field
- func ZapUserAgent(ctx context.Context) zap.Field
- type CounterStat
- type Duration
- type IPAddress
- type LimiterStat
- type RemoteCounterStat
- type SlidingWindow
- type StableSlideValue
- type SubLabels
- type Window
- type WindowHandlerFunc
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ServerAddress 统一的服务器地址 ServerAddress = "127.0.0.1" // LimitServiceName 限流集群服务名 LimitServiceName = "" )
Functions ¶
func CurrentNanosecond ¶
func CurrentNanosecond() int64
CurrentNanosecond obtains the current microsecond, use syscall for better performance
func ParseClientAddr ¶
ParseClientAddr 从ctx中获取客户端连接地址,ip:port形式
func ParseRequestID ¶
ParseRequestID 从ctx中获取requestID
func TimestampMsToUtcIso8601 ¶
TimestampMsToUtcIso8601 格式化时间戳
func WithClientAddr ¶
WithClientAddr ctx增加客户端连接地址
func WithClientIP ¶
WithClientIP ctx增加客户端IP
func WithRequestID ¶
WithRequestID 增加requestID
func WithStructClientIP ¶
WithStructClientIP ctx增加客户端IP
func WithUserAgent ¶
WithUserAgent user agent
func ZapClientAddr ¶
ZapClientAddr 封装clientAddr的日志打印域
func ZapLimitService ¶
ZapLimitService 封装service的打印域
Types ¶
type CounterStat ¶
type CounterStat struct { Key string Namespace string Service string Duration Duration TotalAmount uint32 // 总体的amount SumAmount uint32 // 累加amount StartTime int64 LastMtime int64 NeedUpdateRemote bool RemoteRecordTime int64 }
CounterStat 计数器的状态
type Duration ¶
Duration 自定义Duration
func (Duration) MarshalJSON ¶
MarshalJSON 实现Marshaler
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON 实现Unmarshaler
type LimiterStat ¶
LimiterStat 限制器的状态
type RemoteCounterStat ¶
type RemoteCounterStat struct { Key string StartTime int64 RecordTime int64 RecordServer string SumAmount uint32 }
RemoteCounterStat 远端的counterStat
type SlidingWindow ¶
type SlidingWindow struct {
// contains filtered or unexported fields
}
SlidingWindow 滑窗通用实现
func NewSlidingWindow ¶
func NewSlidingWindow(slideCount int, intervalMs int) *SlidingWindow
NewSlidingWindow 创建滑窗
func (*SlidingWindow) AddAndGetCurrent ¶
func (s *SlidingWindow) AddAndGetCurrent(clientTimeMs int64, serverTimeMs int64, counter uint32) uint32
AddAndGetCurrent 原子增加,并返回当前bucket
type StableSlideValue ¶
type StableSlideValue struct {
// contains filtered or unexported fields
}
StableSlideValue 非当前时间点的静态滑窗值
type WindowHandlerFunc ¶
WindowHandlerFunc 窗口淘汰函数
Click to show internal directories.
Click to hide internal directories.