utils

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ServerAddress 统一的服务器地址
	ServerAddress = "127.0.0.1"
	// LimitServiceName 限流集群服务名
	LimitServiceName = ""
)

Functions

func CurrentMicrosecond

func CurrentMicrosecond() int64

CurrentMicrosecond 获取微秒时间

func CurrentMillisecond

func CurrentMillisecond() int64

CurrentMillisecond 获取微秒时间

func CurrentNanosecond

func CurrentNanosecond() int64

CurrentNanosecond obtains the current microsecond, use syscall for better performance

func IsSuccess

func IsSuccess(code uint32) bool

IsSuccess 是否成功错误码

func IsSysErr

func IsSysErr(code uint32) bool

IsSysErr 是否成功错误码

func IsUserErr

func IsUserErr(code uint32) bool

IsUserErr 是否成功错误码

func ParseClientAddr

func ParseClientAddr(ctx context.Context) string

ParseClientAddr 从ctx中获取客户端连接地址,ip:port形式

func ParseClientIP

func ParseClientIP(ctx context.Context) string

ParseClientIP 从ctx中获取客户端IP

func ParseRequestID

func ParseRequestID(ctx context.Context) string

ParseRequestID 从ctx中获取requestID

func ParseUserAgent

func ParseUserAgent(ctx context.Context) string

ParseUserAgent parse agent

func TimestampMsToUtcIso8601

func TimestampMsToUtcIso8601(timestamp int64) string

TimestampMsToUtcIso8601 格式化时间戳

func WithClientAddr

func WithClientAddr(ctx context.Context, addr string) context.Context

WithClientAddr ctx增加客户端连接地址

func WithClientIP

func WithClientIP(ctx context.Context, ip string) context.Context

WithClientIP ctx增加客户端IP

func WithRequestID

func WithRequestID(ctx context.Context, requestID string) context.Context

WithRequestID 增加requestID

func WithStructClientIP

func WithStructClientIP(ctx context.Context, ip *IPAddress) context.Context

WithStructClientIP ctx增加客户端IP

func WithUserAgent

func WithUserAgent(ctx context.Context, agent string) context.Context

WithUserAgent user agent

func WrapperBool

func WrapperBool(value bool) *wrappers.BoolValue

WrapperBool bool

func WrapperInt64

func WrapperInt64(value int64) *wrappers.Int64Value

WrapperInt64 int64

func WrapperString

func WrapperString(value string) *wrappers.StringValue

WrapperString string

func WrapperUint32

func WrapperUint32(value uint32) *wrappers.UInt32Value

WrapperUint32 uint32

func ZapClientAddr

func ZapClientAddr(ctx context.Context) zap.Field

ZapClientAddr 封装clientAddr的日志打印域

func ZapCode

func ZapCode(code uint32) zap.Field

ZapCode 封装错误码

func ZapLimitKey

func ZapLimitKey(key string) zap.Field

ZapLimitKey 封装key的打印域

func ZapLimitService

func ZapLimitService(service string, namespace string) zap.Field

ZapLimitService 封装service的打印域

func ZapMethod

func ZapMethod(method string) zap.Field

ZapMethod 封装method的日志打印域

func ZapMsgId

func ZapMsgId(msgId int64) zap.Field

ZapMsgId 封装消息ID

func ZapRequestID

func ZapRequestID(ctx context.Context) zap.Field

ZapRequestID 封装RequestID日志打印域

func ZapUserAgent

func ZapUserAgent(ctx context.Context) zap.Field

ZapUserAgent 封装userAgent的日志打印域

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

type Duration time.Duration

Duration 自定义Duration

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON 实现Marshaler

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

UnmarshalJSON 实现Unmarshaler

type IPAddress

type IPAddress struct {
	// 低位, 0-7
	LowValue uint64
	// 高位, 8-15
	HighValue uint64
}

IPAddress IP地址

func NewIPAddress

func NewIPAddress(addr string) *IPAddress

NewIPAddress 创建IP地址数据

func ParseStructClientIP

func ParseStructClientIP(ctx context.Context) *IPAddress

ParseStructClientIP ctx增加客户端IP

func (IPAddress) String

func (addr IPAddress) String() string

转成字符串输出

type LimiterStat

type LimiterStat struct {
	Duration  Duration
	Amount    uint32
	SumAmount uint32
	Cycle     uint64
}

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 非当前时间点的静态滑窗值

func (*StableSlideValue) Reload

func (s *StableSlideValue) Reload(nextStartMs int64, expiredStartMs int64, expireValue uint32)

Reload 重载静态值

func (*StableSlideValue) Value

func (s *StableSlideValue) Value() uint32

Value 获取值

type SubLabels

type SubLabels struct {
	Method string
	AppId  string
	Uin    string
	Labels string
}

SubLabels 复合标签的子标签

func ParseLabels

func ParseLabels(composedLabels string) *SubLabels

ParseLabels 把客户端上报的符合字段,解析成多维度的值

type Window

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

Window 单个窗口

type WindowHandlerFunc

type WindowHandlerFunc func(windowStart int64, counterValue int64)

WindowHandlerFunc 窗口淘汰函数

Jump to

Keyboard shortcuts

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