-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
59 lines (48 loc) · 1.89 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package keycounter
import (
"time"
"github.com/Golang-Tools/optparams"
"github.com/Golang-Tools/redishelper/v2/middlewarehelper"
"github.com/robfig/cron/v3"
)
//Options broker的配置
type Options struct {
MiddlewareOpts []optparams.Option[middlewarehelper.Options] //初始化Middleware的配置
}
//Defaultopt 默认的可选配置
var Defaultopt = Options{
MiddlewareOpts: []optparams.Option[middlewarehelper.Options]{},
}
//m 使用optparams.Option[middlewarehelper.Options]设置中间件属性
func m(opts ...optparams.Option[middlewarehelper.Options]) optparams.Option[Options] {
return optparams.NewFuncOption(func(o *Options) {
if o.MiddlewareOpts == nil {
o.MiddlewareOpts = []optparams.Option[middlewarehelper.Options]{}
}
o.MiddlewareOpts = append(o.MiddlewareOpts, opts...)
})
}
//WithSpecifiedKey 中间件通用设置,指定使用的键,注意设置key后namespace将失效
func WithSpecifiedKey(key string) optparams.Option[Options] {
return m(middlewarehelper.WithSpecifiedKey(key))
}
//WithKey 中间件通用设置,指定使用的键,注意设置后namespace依然有效
func WithKey(key string) optparams.Option[Options] {
return m(middlewarehelper.WithKey(key))
}
//WithNamespace 中间件通用设置,指定锁的命名空间
func WithNamespace(ns ...string) optparams.Option[Options] {
return m(middlewarehelper.WithNamespace(ns...))
}
//WithMaxTTL 设置token消减间隔时长,单位s
func WithMaxTTL(maxTTL time.Duration) optparams.Option[Options] {
return m(middlewarehelper.WithMaxTTL(maxTTL))
}
//WithAutoRefreshInterval 设置自动刷新过期时间的设置
func WithAutoRefreshInterval(autoRefreshInterval string) optparams.Option[Options] {
return m(middlewarehelper.WithAutoRefreshInterval(autoRefreshInterval))
}
//WithTaskCron 设置定时器
func WithTaskCron(taskCron *cron.Cron) optparams.Option[Options] {
return m(middlewarehelper.WithTaskCron(taskCron))
}