1 Star 0 Fork 0

ClickVisual/casbin-redis-watcher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
options.go 2.22 KB
一键复制 编辑 原始数据 按行查看 历史
MEX7 提交于 2022-08-10 18:02 . init
package rediswatcher
import (
"time"
"github.com/go-redis/redis/v8"
)
type WatcherOptions struct {
Channel string
PubConn *redis.Client
SubConn *redis.Client
Username string
Password string
Protocol string
IgnoreSelf bool
LocalID string
RecordMetrics func(*WatcherMetrics)
SquashMessages bool
SquashTimeoutShort time.Duration
SquashTimeoutLong time.Duration
callbackPending bool
}
type WatcherOption func(*WatcherOptions)
func Channel(subject string) WatcherOption {
return func(options *WatcherOptions) {
options.Channel = subject
}
}
func Username(username string) WatcherOption {
return func(options *WatcherOptions) {
options.Username = username
}
}
func Password(password string) WatcherOption {
return func(options *WatcherOptions) {
options.Password = password
}
}
func Protocol(protocol string) WatcherOption {
return func(options *WatcherOptions) {
options.Protocol = protocol
}
}
func WithRedisSubConnection(connection *redis.Client) WatcherOption {
return func(options *WatcherOptions) {
options.SubConn = connection
}
}
func WithRedisPubConnection(connection *redis.Client) WatcherOption {
return func(options *WatcherOptions) {
options.PubConn = connection
}
}
func LocalID(id string) WatcherOption {
return func(options *WatcherOptions) {
options.LocalID = id
}
}
func IgnoreSelf(ignore bool) WatcherOption {
return func(options *WatcherOptions) {
options.IgnoreSelf = ignore
}
}
func SquashMessages(squash bool) WatcherOption {
return func(options *WatcherOptions) {
options.SquashMessages = squash
}
}
func RecordMetrics(callback func(*WatcherMetrics)) WatcherOption {
return func(options *WatcherOptions) {
options.RecordMetrics = callback
}
}
func SquashTimeoutShort(d time.Duration) WatcherOption {
return func(options *WatcherOptions) {
options.SquashTimeoutShort = d
}
}
func SquashTimeoutLong(d time.Duration) WatcherOption {
return func(options *WatcherOptions) {
options.SquashTimeoutLong = d
}
}
// IsCallbackPending
func IsCallbackPending(w *Watcher, shouldClear bool) bool {
r := w.options.callbackPending
if shouldClear {
w.options.callbackPending = false
}
return r
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/clickvisual/casbin-redis-watcher.git
git@gitee.com:clickvisual/casbin-redis-watcher.git
clickvisual
casbin-redis-watcher
casbin-redis-watcher
main

搜索帮助