Documentation ¶
Index ¶
- func DeepClone(v interface{}) interface{}
- func DeepCopy(dst, src interface{})
- func DispatchReadPK(money float64, amount int, average bool) (pks []float64)
- func Exists(path string) bool
- func FormatTime2String(t time.Time) string
- func GetIrisRemoteAddr(ctx *context.Context) string
- func GetMD5Hash(text string) string
- func IsDir(path string) bool
- func IsFile(path string) bool
- func RandGroup(p ...uint32) int
- func RandInterval(b1, b2 int32) int32
- func RandIntervalN(b1, b2 int32, n uint32) []int32
- func RandString(len int) string
- 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 LazyQueue
- type LimiterMap
- func (l *LimiterMap) Add(key interface{}, limit int64)
- func (l *LimiterMap) Clean()
- func (l *LimiterMap) Del(key interface{})
- func (l *LimiterMap) IsLimited(key interface{}, seconds int64) bool
- func (l *LimiterMap) UnSafeDel(key interface{})
- func (l *LimiterMap) UnsafeAdd(key interface{}, limit int64)
- 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()
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 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 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 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(key interface{})
PushToQueue 将不重要的对象加入保存队列
type LimiterMap ¶
var Limiter *LimiterMap
func (*LimiterMap) Add ¶
func (l *LimiterMap) Add(key interface{}, limit int64)
func (*LimiterMap) Del ¶
func (l *LimiterMap) Del(key interface{})
func (*LimiterMap) IsLimited ¶
func (l *LimiterMap) IsLimited(key interface{}, seconds int64) bool
func (*LimiterMap) UnSafeDel ¶
func (l *LimiterMap) UnSafeDel(key interface{})
func (*LimiterMap) UnsafeAdd ¶ added in v1.1.2
func (l *LimiterMap) UnsafeAdd(key interface{}, limit int64)
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 获取已排序数据