goProject/.svn/pristine/1b/1b511d8dc10711a9b500c6dea251529f59d249f0.svn-base
2025-01-06 16:21:36 +08:00

35 lines
765 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### 窗口周期计数器
窗口周期计数类,用于记录一个窗口周期数量,并且触发某个操作的场景。
在下一个窗口周期会自动重置次数
#### =======================>使用方法说明<=========================
1.引入包
2.构造对象并次有
3.调用对象的增加次数方法
```go
package demo
import (
"time"
"goutil/counter_util"
)
func main() {
// 构造名字叫test的窗口间隔为1s计数达到2就会触发警告的窗口计数器
c := counter_util.NewCounterUtil("test", 2, checkId, func(tag string, num int, ti time.Time) {
//自定义触发动作
})
c.AddNum(1)
c.AddNum(10)
}
// 窗口周期设定为1s
func checkId(t1, t2 time.Time) bool {
return t1.Second() == t2.Second()
}
```