utils

package
v0.0.0-...-0a821e7 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetContextClaims

func GetContextClaims(ctx *gin.Context) (*jwt.TokenClaims, error)

GetContextClaims 从上下文中获取当前请求接口的Claims

func GetOutboundIP

func GetOutboundIP() string

func GetOutboundIPByInterface

func GetOutboundIPByInterface() string

func GetOutboundIPByUDP

func GetOutboundIPByUDP() string

func IsDir

func IsDir(path string) (bool, error)

IsDir 判断所给路径是否为文件夹

func IsFile

func IsFile(path string) (bool, error)

IsFile 判断所给路径是否为文件

func IsTestNetwork

func IsTestNetwork(ip string) bool

func Md5

func Md5(s string) string

func PathExists

func PathExists(path string) (bool, error)

PathExists 判断所给路径文件/文件夹是否存在

func Sha1

func Sha1(s string) string

func Sha256

func Sha256(s string) string

func Sha512

func Sha512(s string) string

Types

type Discovery

type Discovery[T any] interface {
	DiscoverServices(s string) ([]T, error)
}

type Instance

type Instance interface {
	GetInstanceID() string
	GetAddress() string
}

type LoadBalanceStrategy

type LoadBalanceStrategy int

LoadBalanceStrategy 负载均衡策略

const (
	RoundRobin       LoadBalanceStrategy = iota // 轮询
	Random                                      // 随机
	LeastConnections                            // 最少连接
)

type LoadBalancer

type LoadBalancer[T Instance] struct {
	// contains filtered or unexported fields
}

LoadBalancer 负载均衡器

func NewLoadBalancer

func NewLoadBalancer[T Instance](discovery Discovery[T], strategy LoadBalanceStrategy) *LoadBalancer[T]

NewLoadBalancer 创建负载均衡器

func (*LoadBalancer[T]) GetInstanceStats

func (lb *LoadBalancer[T]) GetInstanceStats(serviceName string) (map[string]int, error)

GetInstanceStats 获取统计信息

func (*LoadBalancer[T]) GetServiceInstance

func (lb *LoadBalancer[T]) GetServiceInstance(serviceName string) (T, error)

GetServiceInstance 获取服务实例

func (*LoadBalancer[T]) ReleaseConnection

func (lb *LoadBalancer[T]) ReleaseConnection(instanceID string)

ReleaseConnection 释放连接

type LocksmithLogger

type LocksmithLogger interface {
	logger.LogCtxInterface
}

type LocksmithMutex

type LocksmithMutex interface {
	NewMutex(name string, options ...redsync.Option) *redsync.Mutex
}

type Mutex

type Mutex interface {
	Lock() error
	TryLock() error
	Unlock() (bool, error)
	Extend() (bool, error)
	Name() string
	Until() time.Time
}

type RedisLock

type RedisLock struct {
	Mutex
	// contains filtered or unexported fields
}

func (*RedisLock) Lock

func (l *RedisLock) Lock(ctx context.Context, extend bool) error

Lock 会多次尝试(defaultMaxRetries 次), 如果尝试次数内还未获取到锁则返回错误

func (*RedisLock) TryLock

func (l *RedisLock) TryLock(ctx context.Context, extend bool) error

TryLock 获取不到锁直接返回错误

func (*RedisLock) Unlock

func (l *RedisLock) Unlock() error

Unlock 解锁

type RedisLocksmith

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

func NewRedisLocksmith

func NewRedisLocksmith(logger LocksmithLogger, redisClient *redis.CommonRedisClient) *RedisLocksmith

func (*RedisLocksmith) NewLock

func (r *RedisLocksmith) NewLock(t constant.Prefix, object ...string) *RedisLock

NewLock 创建锁

Jump to

Keyboard shortcuts

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