1 Star 0 Fork 0

jack/protoactor-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
config.go 1.55 KB
一键复制 编辑 原始数据 按行查看 历史
490689386@qq.com 提交于 2025-05-19 14:50 +08:00 . 初始化
package zk
import (
"time"
)
const baseKey = `/protoactor`
type Option func(*config)
// WithAuth set zk auth
func WithAuth(scheme string, credential string) Option {
return func(o *config) {
o.Auth = authConfig{Scheme: scheme, Credential: credential}
}
}
// WithBaseKey set actors base key
func WithBaseKey(key string) Option {
return func(o *config) {
if isStrBlank(key) {
o.BaseKey = baseKey
} else {
o.BaseKey = formatBaseKey(key)
}
}
}
// WithSessionTimeout set zk session timeout
func WithSessionTimeout(tm time.Duration) Option {
return func(o *config) {
o.SessionTimeout = tm
}
}
// WithRoleChangedListener triggered on self role changed
func WithRoleChangedListener(l RoleChangedListener) Option {
return func(o *config) {
o.RoleChanged = l
}
}
func WithRoleChangedFunc(f OnRoleChangedFunc) Option {
return func(o *config) {
o.RoleChanged = f
}
}
func withEndpoints(e []string) Option {
return func(o *config) {
o.Endpoints = e
}
}
type authConfig struct {
Scheme string
Credential string
}
func (za authConfig) isEmpty() bool {
return za.Scheme == "" && za.Credential == ""
}
type RoleChangedListener interface {
OnRoleChanged(RoleType)
}
type OnRoleChangedFunc func(RoleType)
func (fn OnRoleChangedFunc) OnRoleChanged(rt RoleType) {
fn(rt)
}
type config struct {
BaseKey string
Endpoints []string
SessionTimeout time.Duration
Auth authConfig
RoleChanged RoleChangedListener
}
func defaultConfig() *config {
return &config{
BaseKey: baseKey,
SessionTimeout: time.Second * 10,
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wujianhai/protoactor-go.git
git@gitee.com:wujianhai/protoactor-go.git
wujianhai
protoactor-go
protoactor-go
5633fe2499dd

搜索帮助