Ai
1 Star 0 Fork 0

朽木木/gost-core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
selector.go 997 Bytes
一键复制 编辑 原始数据 按行查看 历史
ginuerzh 提交于 2022-09-04 13:22 +08:00 . update selector
package selector
import (
"context"
"sync/atomic"
"time"
)
type Selector[T any] interface {
Select(context.Context, ...T) T
}
type Strategy[T any] interface {
Apply(context.Context, ...T) T
}
type Filter[T any] interface {
Filter(context.Context, ...T) []T
}
type Markable interface {
Marker() Marker
}
type Marker interface {
Time() time.Time
Count() int64
Mark()
Reset()
}
type failMarker struct {
failTime int64
failCount int64
}
func NewFailMarker() Marker {
return &failMarker{}
}
func (m *failMarker) Time() time.Time {
if m == nil {
return time.Time{}
}
return time.Unix(atomic.LoadInt64(&m.failTime), 0)
}
func (m *failMarker) Count() int64 {
if m == nil {
return 0
}
return atomic.LoadInt64(&m.failCount)
}
func (m *failMarker) Mark() {
if m == nil {
return
}
atomic.AddInt64(&m.failCount, 1)
atomic.StoreInt64(&m.failTime, time.Now().Unix())
}
func (m *failMarker) Reset() {
if m == nil {
return
}
atomic.StoreInt64(&m.failCount, 0)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hao_shen/gost-core.git
git@gitee.com:hao_shen/gost-core.git
hao_shen
gost-core
gost-core
v1.1.1

搜索帮助