-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
optinos.go
85 lines (70 loc) · 1.72 KB
/
optinos.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package xxl
import (
"github.com/go-basic/ipv4"
"time"
)
type Options struct {
ServerAddr string `json:"server_addr"` //调度中心地址
AccessToken string `json:"access_token"` //请求令牌
Timeout time.Duration `json:"timeout"` //接口超时时间
ExecutorIp string `json:"executor_ip"` //本地(执行器)IP(可自行获取)
ExecutorPort string `json:"executor_port"` //本地(执行器)端口
RegistryKey string `json:"registry_key"` //执行器名称
LogDir string `json:"log_dir"` //日志目录
l Logger //日志处理
}
func newOptions(opts ...Option) Options {
opt := Options{
ExecutorIp: ipv4.LocalIP(),
ExecutorPort: DefaultExecutorPort,
RegistryKey: DefaultRegistryKey,
}
for _, o := range opts {
o(&opt)
}
if opt.l == nil {
opt.l = &logger{}
}
return opt
}
type Option func(o *Options)
var (
DefaultExecutorPort = "9999"
DefaultRegistryKey = "golang-jobs"
)
// ServerAddr 设置调度中心地址
func ServerAddr(addr string) Option {
return func(o *Options) {
o.ServerAddr = addr
}
}
// AccessToken 请求令牌
func AccessToken(token string) Option {
return func(o *Options) {
o.AccessToken = token
}
}
// ExecutorIp 设置执行器IP
func ExecutorIp(ip string) Option {
return func(o *Options) {
o.ExecutorIp = ip
}
}
// ExecutorPort 设置执行器端口
func ExecutorPort(port string) Option {
return func(o *Options) {
o.ExecutorPort = port
}
}
// RegistryKey 设置执行器标识
func RegistryKey(registryKey string) Option {
return func(o *Options) {
o.RegistryKey = registryKey
}
}
// SetLogger 设置日志处理器
func SetLogger(l Logger) Option {
return func(o *Options) {
o.l = l
}
}