limit
This commit is contained in:
parent
d1433040df
commit
49b7b09516
20
limit.go
20
limit.go
|
|
@ -20,21 +20,25 @@ type WindowsLimit struct {
|
|||
option *WindowsLimitOption
|
||||
}
|
||||
|
||||
func NewWindowsLimitOption() *WindowsLimitOption {
|
||||
return &WindowsLimitOption{
|
||||
Key: fmt.Sprintf("windows:limit:%s:%d", time.Now().Format("20060102"), time.Now().UnixMilli()),
|
||||
Count: 1000,
|
||||
Size: time.Second * 60,
|
||||
}
|
||||
}
|
||||
|
||||
func NewWindowsLimit(client *redis.Client, option *WindowsLimitOption) *WindowsLimit {
|
||||
option.Default()
|
||||
return &WindowsLimit{
|
||||
client: client,
|
||||
option: option,
|
||||
}
|
||||
}
|
||||
|
||||
func (o *WindowsLimitOption) Default() {
|
||||
if o.Key == "" {
|
||||
o.Key = fmt.Sprintf("windows:limit:%s:%d", time.Now().Format("20060102"), time.Now().UnixMilli())
|
||||
}
|
||||
if o.Count <= 0 {
|
||||
o.Count = 1000
|
||||
}
|
||||
if o.Size <= 0 {
|
||||
o.Size = time.Second * 60
|
||||
}
|
||||
}
|
||||
func (w *WindowsLimit) tidy() {
|
||||
now := time.Now().UnixMilli()
|
||||
start := now - w.option.Size.Milliseconds()
|
||||
|
|
|
|||
Loading…
Reference in New Issue