Documentation ¶
Index ¶
- func Auth01Validate(auth int64, operation int) bool
- func DeepClone(v interface{}) interface{}
- func DeepCopy(dst, src interface{})
- func DispatchReadPK(money float64, amount int, average bool) (pks []float64)
- func ExistedCache(key string) bool
- func Exists(path string) bool
- func FormatTime2String(t time.Time) string
- func GetIrisRemoteAddr(ctx *context.Context) string
- func GetMD5Hash(text string) string
- func GetTodayUnix() int64
- func GetTomorrowUnix() int64
- func IsDir(path string) bool
- func IsEmail(email string) bool
- func IsFile(path string) bool
- func IsPhone(phoneStr string) bool
- func RDLockOp(operation string) (release func(), got bool, wait chan struct{})
- func RDLockOpTimeout(operation string, timeout time.Duration) (release func(), got bool, wait chan struct{})
- func RDLockOpWait(operation string) func()
- func RDLockOpWaitTimeout(operation string, timeout time.Duration) func()
- func RDLockOpWithContext(ctx context.Context, operation string) (func(), bool)
- func RandGroup(p ...uint32) int
- func RandInterval(b1, b2 int32) int32
- func RandIntervalN(b1, b2 int32, n uint32) []int32
- func RandItemWeight(rd *rand.Rand, data map[interface{}]int64) (interface{}, error)
- func RandString(len int) string
- func ReplaceKeyword(cfg, value string) string
- func Reverse(s interface{})
- func RunCmd(command string, args ...string) error
- func SignalExit(callback func())
- func SyncObjByStr(objKey string) func()
- func SyncStrWithTimeout(objKey string, duration time.Duration) func()
- type AuthValidator
- type LazyQueue
- func (lazy *LazyQueue) Executed(f func(interface{}, error))
- func (lazy *LazyQueue) Length() int
- func (lazy *LazyQueue) OutOfQueue(key interface{})
- func (lazy *LazyQueue) PushToQueue(obj interface{})
- func (lazy *LazyQueue) PushToQueueWait(obj interface{})
- func (lazy *LazyQueue) Queued(f func(interface{}))
- func (lazy *LazyQueue) Reset()
- func (lazy *LazyQueue) Run()
- type LimiterMap
- func (l *LimiterMap) Add(key interface{}, duration time.Duration)
- func (l *LimiterMap) Clean()
- func (l *LimiterMap) Del(key interface{})
- func (l *LimiterMap) IsLimited(key interface{}, seconds int64) bool
- func (l *LimiterMap) IsV2Limited(key interface{}, duration time.Duration, max int64) (bool, int64)
- func (l *LimiterMap) UnSafeDel(key interface{})
- func (l *LimiterMap) UnsafeAdd(key interface{}, duration time.Duration)
- type RankItem
- type RateLimiter
- type RkPool
- func (rp *RkPool) Clean()
- func (rp *RkPool) GetNO1() *RankItem
- func (rp *RkPool) GetRankData(from, to int) (data []RankItem)
- func (rp *RkPool) IsInPool(item RankItem) bool
- func (rp *RkPool) Queue(item RankItem)
- func (rp *RkPool) Rank()
- func (rp *RkPool) Remove(key interface{})
- func (rp *RkPool) Serve()
- type Waiter
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Auth01Validate ¶ added in v1.2.6
Auth01Validate 验证操权限值和操作值
func DeepClone ¶
func DeepClone(v interface{}) interface{}
DeepClone v
Example ¶
package main import ( "fmt" "github.com/helloh2o/lucky/utils" ) func main() { src := []int{1, 2, 3} dst := utils.DeepClone(src).([]int) for _, v := range dst { fmt.Println(v) } }
Output: 1 2 3
func DeepCopy ¶
func DeepCopy(dst, src interface{})
DeepCopy src to dst
Example ¶
package main import ( "fmt" "github.com/helloh2o/lucky/utils" ) func main() { src := []int{1, 2, 3} var dst []int utils.DeepCopy(&dst, &src) for _, v := range dst { fmt.Println(v) } }
Output: 1 2 3
func DispatchReadPK ¶
DispatchReadPK random || @average money/amount
func FormatTime2String ¶ added in v1.1.7
FormatTime2String 时间to字符串
func GetIrisRemoteAddr ¶ added in v1.1.7
GetIrisRemoteAddr 获取Iris 客户端IP
func RDLockOpTimeout ¶ added in v1.2.0
func RDLockOpTimeout(operation string, timeout time.Duration) (release func(), got bool, wait chan struct{})
RDLockOpTimeout redis 分布式锁, 时间不够可能引发并发同步问题 release释放,got 是否获取锁,wait在线等待,直到获取锁
func RDLockOpWait ¶ added in v1.2.7
func RDLockOpWait(operation string) func()
RDLockOpWait redis 等待分布式锁,直到获取锁
func RDLockOpWaitTimeout ¶ added in v1.3.8
RDLockOpWaitTimeout 自定义超时操作
func RDLockOpWithContext ¶ added in v1.3.8
RDLockOpWithContext redis 上下文获取锁
func RandGroup ¶
RandGroup by []unit32
Example ¶
package main import ( "fmt" "github.com/helloh2o/lucky/utils" ) func main() { i := utils.RandGroup(0, 0, 50, 50) switch i { case 2, 3: fmt.Println("ok") } }
Output: ok
func RandInterval ¶
RandInterval b1 to b2
Example ¶
package main import ( "fmt" "github.com/helloh2o/lucky/utils" ) func main() { v := utils.RandInterval(-1, 1) switch v { case -1, 0, 1: fmt.Println("ok") } }
Output: ok
func RandIntervalN ¶
RandIntervalN b1, b2, n
Example ¶
package main import ( "fmt" "github.com/helloh2o/lucky/utils" ) func main() { r := utils.RandIntervalN(-1, 0, 2) if r[0] == -1 && r[1] == 0 || r[0] == 0 && r[1] == -1 { fmt.Println("ok") } }
Output: ok
func RandItemWeight ¶ added in v1.2.2
RandItemWeight 根据权重随机
func ReplaceKeyword ¶ added in v1.2.3
ReplaceKeyword 替换关键字
func Reverse ¶ added in v1.4.5
func Reverse(s interface{})
Reverse Answers for Go version 1.20 and earlier:
func SignalExit ¶ added in v1.1.7
func SignalExit(callback func())
func SyncObjByStr ¶ added in v1.1.6
func SyncObjByStr(objKey string) func()
SyncObjByStr 锁定一个字符串的同步操作
func SyncStrWithTimeout ¶ added in v1.1.7
SyncStrWithTimeout 锁定一个字符串的同步操作,允许过期
Types ¶
type AuthValidator ¶ added in v1.2.3
func NewAuthValidator ¶ added in v1.2.3
func NewAuthValidator() *AuthValidator
NewAuthValidator 创建一个权限检验器
func (*AuthValidator) AddAuthData ¶ added in v1.2.3
func (au *AuthValidator) AddAuthData(key interface{}, maxAuth int)
AddAuthData 添加对象权限
func (*AuthValidator) GetAuth ¶ added in v1.2.3
func (au *AuthValidator) GetAuth(key interface{}) int
GetAuth 获取对象的权限值
func (*AuthValidator) Validate ¶ added in v1.2.3
func (au *AuthValidator) Validate(key interface{}, operation int) bool
Validate 验证操作是否有权限
type LazyQueue ¶ added in v1.1.5
LazyQueue 排队保存,重复的数据只排一次,时效性一般的情况,场景:降低数据库写压力
func NewLazyQueue ¶ added in v1.1.4
func (*LazyQueue) OutOfQueue ¶ added in v1.1.5
func (lazy *LazyQueue) OutOfQueue(key interface{})
OutOfQueue 解除对象慢保存排队
func (*LazyQueue) PushToQueue ¶ added in v1.1.5
func (lazy *LazyQueue) PushToQueue(obj interface{})
PushToQueue 对象加入保存队列
func (*LazyQueue) PushToQueueWait ¶ added in v1.2.2
func (lazy *LazyQueue) PushToQueueWait(obj interface{})
PushToQueueWait 对象同步加入保存队列
type LimiterMap ¶
var Limiter *LimiterMap
func (*LimiterMap) Add ¶
func (l *LimiterMap) Add(key interface{}, duration time.Duration)
func (*LimiterMap) Del ¶
func (l *LimiterMap) Del(key interface{})
func (*LimiterMap) IsLimited ¶
func (l *LimiterMap) IsLimited(key interface{}, seconds int64) bool
func (*LimiterMap) IsV2Limited ¶ added in v1.1.9
func (*LimiterMap) UnSafeDel ¶
func (l *LimiterMap) UnSafeDel(key interface{})
func (*LimiterMap) UnsafeAdd ¶ added in v1.1.2
func (l *LimiterMap) UnsafeAdd(key interface{}, duration time.Duration)
type RankItem ¶ added in v1.1.5
type RankItem struct { // 键 Key interface{} // 原始值 Data interface{} // 排名值 RankVal int64 }
RankItem 排序项目
type RateLimiter ¶ added in v1.1.3
type RateLimiter struct {
// contains filtered or unexported fields
}
From:: https://github.com/beefsack/go-rate/blob/master/rate.go A RateLimiter limits the rate at which an action can be performed. It applies neither smoothing (like one could achieve in a token bucket system) nor does it offer any conception of warmup, wherein the rate of actions granted are steadily increased until a steady throughput equilibrium is reached.
func New ¶ added in v1.1.3
func New(limit int, interval time.Duration) *RateLimiter
New creates a new rate limiter for the limit and interval.
func (*RateLimiter) Try ¶ added in v1.1.3
func (r *RateLimiter) Try() (ok bool, remaining time.Duration)
Try returns true if under the rate limit, or false if over and the remaining time before the rate limit expires.
func (*RateLimiter) Wait ¶ added in v1.1.3
func (r *RateLimiter) Wait()
Wait blocks if the rate limit has been reached. Wait offers no guarantees of fairness for multiple actors if the allowed rate has been temporarily exhausted.
type RkPool ¶ added in v1.1.5
type RkPool struct {
// contains filtered or unexported fields
}
RankPool 排序池
func NewRKPool ¶ added in v1.1.5
func NewRKPool(name string, size int, rankCycle time.Duration, selfSort func([]RankItem) []RankItem) *RkPool
NewRKPool 创建一个新的排序池
func (*RkPool) GetRankData ¶ added in v1.1.5
GetRankData 获取已排序数据