-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
73 lines (61 loc) · 1.61 KB
/
option.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
package msa
import (
"os"
"time"
"github.com/go-god/gdi"
"github.com/go-god/gdi/factory"
"github.com/go-god/msa/config"
"github.com/go-god/msa/logger"
"github.com/go-god/msa/provides"
)
// Option engine option
type Option func(e *Engine)
// WithGracefulWait set engine gracefulWait.
func WithGracefulWait(t time.Duration) Option {
return func(e *Engine) {
e.gracefulWait = t
}
}
// WithInjector set injector
// inject type as: factory.FbInject or factory.DigInject
func WithInjector(injectType factory.InjectType) Option {
return func(e *Engine) {
e.injector = factory.CreateDI(injectType)
}
}
// WithInjectValues set inject object
func WithInjectValues(objects ...*gdi.Object) Option {
return func(e *Engine) {
e.injectValues = append(e.injectValues, objects...)
}
}
// WithInterruptSignals set engine interruptSignals
func WithInterruptSignals(signals ...os.Signal) Option {
return func(e *Engine) {
e.interruptSignals = append(e.interruptSignals, signals...)
}
}
// WithConfigInterface set config read interface
func WithConfigInterface(c config.ConfigInterface) Option {
return func(e *Engine) {
e.configInterface = c
}
}
// WithProviders add providers
func WithProviders(provides ...provides.Provider) Option {
return func(e *Engine) {
e.providers = append(e.providers, provides...)
}
}
// WithConfigProvider add config providers
func WithConfigProvider(configProvider provides.ConfigProvider) Option {
return func(e *Engine) {
e.configProvider = configProvider
}
}
// WithLogger logger config
func WithLogger(opts ...logger.Option) Option {
return func(e *Engine) {
logger.Default(opts...)
}
}