pkg

package
v0.2.30 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 12 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	LogLevelDebug = LogLevel(0)
	LogLevelInfo  = LogLevel(1)
	LogLevelWarn  = LogLevel(2)
	LogLevelError = LogLevel(3)
)

Variables

View Source
var (
	ErrClientNotSupport          = errors.New("this feature client not support")
	ErrServerNotSupport          = errors.New("this feature server not support")
	ErrRequestInvalid            = errors.New("request invalid")
	ErrLackResponseChan          = errors.New("lack response chan")
	ErrDuplicateResponseReceived = errors.New("duplicate response received")
	ErrMethodNotSupport          = errors.New("method not support")
	ErrJSONUnmarshal             = errors.New("json unmarshal error")
	ErrSessionHasNotInitialized  = errors.New("the session has not been initialized")
	ErrLackSession               = errors.New("lack session")
	ErrSessionClosed             = errors.New("session closed")
	ErrSendEOF                   = errors.New("send EOF")
	ErrRateLimitExceeded         = errors.New("rate limit exceeded")
)

Functions

func B2S

func B2S(b []byte) string

func JSONUnmarshal added in v0.1.7

func JSONUnmarshal(data []byte, v interface{}) error

func JoinErrors

func JoinErrors(errs []error) error

func NewCancelShieldContext added in v0.2.0

func NewCancelShieldContext(ctx context.Context) context.Context

func Recover

func Recover()

func RecoverWithFunc

func RecoverWithFunc(f func(r any))

Types

type AtomicBool added in v0.1.10

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

func NewAtomicBool added in v0.1.10

func NewAtomicBool() *AtomicBool

func (*AtomicBool) Load added in v0.1.10

func (b *AtomicBool) Load() bool

func (*AtomicBool) Store added in v0.1.10

func (b *AtomicBool) Store(value bool)

type AtomicString added in v0.2.0

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

func NewAtomicString added in v0.2.0

func NewAtomicString() *AtomicString

func (*AtomicString) Load added in v0.2.0

func (b *AtomicString) Load() string

func (*AtomicString) Store added in v0.2.0

func (b *AtomicString) Store(value string)

type CancelShieldContext added in v0.2.0

type CancelShieldContext struct {
	context.Context
}

func (CancelShieldContext) Deadline added in v0.2.0

func (v CancelShieldContext) Deadline() (deadline time.Time, ok bool)

func (CancelShieldContext) Done added in v0.2.0

func (v CancelShieldContext) Done() <-chan struct{}

func (CancelShieldContext) Err added in v0.2.0

func (v CancelShieldContext) Err() error

type LogLevel

type LogLevel uint32

type Logger

type Logger interface {
	Debugf(format string, a ...any)
	Infof(format string, a ...any)
	Warnf(format string, a ...any)
	Errorf(format string, a ...any)
}
var DebugLogger Logger = &defaultLogger{
	logLevel: LogLevelDebug,
	infoLog:  log.New(os.Stdout, "", log.LstdFlags|log.Lshortfile),
	errLog:   log.New(os.Stderr, "", log.LstdFlags|log.Lshortfile),
}
var DefaultLogger Logger = &defaultLogger{
	logLevel: LogLevelInfo,
	infoLog:  log.New(os.Stdout, "", log.LstdFlags|log.Lshortfile),
	errLog:   log.New(os.Stderr, "", log.LstdFlags|log.Lshortfile),
}

type Rate added in v0.2.7

type Rate struct {
	Limit float64 // 每秒允许的请求数
	Burst int     // 突发请求上限
}

Rate 定义速率限制参数

type RateLimiter added in v0.2.7

type RateLimiter interface {
	Allow(toolName string) bool
}

RateLimiter 定义速率限制接口

type ResponseError

type ResponseError struct {
	Code    int
	Message string
	Data    interface{}
}

func NewResponseError

func NewResponseError(code int, message string, data interface{}) *ResponseError

func (*ResponseError) Error

func (e *ResponseError) Error() string

type SyncMap

type SyncMap[V any] struct {
	// contains filtered or unexported fields
}

func (*SyncMap[V]) Delete

func (m *SyncMap[V]) Delete(key string)

func (*SyncMap[V]) Load

func (m *SyncMap[V]) Load(key string) (value V, ok bool)

func (*SyncMap[V]) LoadAndDelete

func (m *SyncMap[V]) LoadAndDelete(key string) (value V, loaded bool)

func (*SyncMap[V]) LoadOrStore

func (m *SyncMap[V]) LoadOrStore(key string, value V) (actual V, loaded bool)

func (*SyncMap[V]) Range

func (m *SyncMap[V]) Range(f func(key string, value V) bool)

func (*SyncMap[V]) Store

func (m *SyncMap[V]) Store(key string, value V)

type TokenBucketLimiter added in v0.2.7

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

TokenBucketLimiter 令牌桶限速器实现

func NewTokenBucketLimiter added in v0.2.7

func NewTokenBucketLimiter(defaultRate Rate) *TokenBucketLimiter

NewTokenBucketLimiter 创建新的令牌桶限速器

func (*TokenBucketLimiter) Allow added in v0.2.7

func (l *TokenBucketLimiter) Allow(toolName string) bool

Allow 检查请求是否被允许

func (*TokenBucketLimiter) SetToolLimit added in v0.2.7

func (l *TokenBucketLimiter) SetToolLimit(toolName string, rate Rate)

SetToolLimit 为特定工具设置限制

Jump to

Keyboard shortcuts

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