/
options.go
78 lines (62 loc) · 1.28 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package app
/**
* created by mengqi on 2023/11/13
* 这里使用函数选项模式
*/
import (
"net/url"
"os"
"time"
"github.com/chaos-ma/chaos/registry"
"github.com/chaos-ma/chaos/server/httpserver"
"github.com/chaos-ma/chaos/server/rpcserver"
)
type Option func(o *options)
type options struct {
id string
endpoints []*url.URL
name string
sigs []os.Signal
//允许用户传入自己的实现
registrar registry.Registrar
registrarTimeout time.Duration
//stop超时时间
stopTimeout time.Duration
restServer *httpserver.Server
rpcServer *rpcserver.Server
}
func WithRegistrar(registrar registry.Registrar) Option {
return func(o *options) {
o.registrar = registrar
}
}
func WithEndpoints(endpoints []*url.URL) Option {
return func(o *options) {
o.endpoints = endpoints
}
}
func WithRPCServer(server *rpcserver.Server) Option {
return func(o *options) {
o.rpcServer = server
}
}
func WithRestServer(server *httpserver.Server) Option {
return func(o *options) {
o.restServer = server
}
}
func WithID(id string) Option {
return func(o *options) {
o.id = id
}
}
func WithName(name string) Option {
return func(o *options) {
o.name = name
}
}
func WithSigs(sigs []os.Signal) Option {
return func(o *options) {
o.sigs = sigs
}
}