-
Notifications
You must be signed in to change notification settings - Fork 3
/
options.go
52 lines (41 loc) · 966 Bytes
/
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
package zmicro
import (
"github.com/zmicro-team/zmicro/core/config"
"github.com/zmicro-team/zmicro/core/transport/http"
"github.com/zmicro-team/zmicro/core/transport/rpc/server"
)
type BeforeFunc func() error
type Options struct {
InitRpcServer server.InitRpcServerFunc
InitHttpServer http.InitHttpServerFunc
ConfigCallbacks []func(config.IConfig)
Before BeforeFunc
}
type Option func(*Options)
func newOptions(opts ...Option) Options {
options := Options{}
for _, o := range opts {
o(&options)
}
return options
}
func InitRpcServer(f server.InitRpcServerFunc) Option {
return func(o *Options) {
o.InitRpcServer = f
}
}
func InitHttpServer(f http.InitHttpServerFunc) Option {
return func(o *Options) {
o.InitHttpServer = f
}
}
func ConfigCallbacks(f ...func(config.IConfig)) Option {
return func(o *Options) {
o.ConfigCallbacks = f
}
}
func Before(f BeforeFunc) Option {
return func(o *Options) {
o.Before = f
}
}