-
Notifications
You must be signed in to change notification settings - Fork 60
/
options.go
120 lines (102 loc) · 3.15 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package archaius
import (
"crypto/tls"
"github.com/go-chassis/go-archaius/source/util"
)
// RemoteInfo has attribute for config center source initialization
type RemoteInfo struct {
//required.
//Key value can be in different namespace, we call it dimension.
//although key is same but in different dimension, the value is different.
//you must specify the service,app and version, so that the remote source will pull key value
DefaultDimension map[string]string
//archaius config center source support 2 types of refresh mechanism:
//0: Web-Socket Based - client makes an web socket connection with
//the config server and keeps getting an events whenever any data changes.
//1: Pull Configuration interval- In this type client keeps polling the configuration from
//the config server at regular intervals.
RefreshMode int
//Pull Configuration interval, unit is second
RefreshInterval int
//currentConfig for config client implementation
//if you already create a client, don't need to set those config
URL string
TenantName string
EnableSSL bool
TLSConfig *tls.Config
AutoDiscovery bool
APIVersion string
RefreshPort string
ProjectID string
}
//Options hold options
type Options struct {
RequiredFiles []string
OptionalFiles []string
FileHandler util.FileHandler
RemoteInfo *RemoteInfo
RemoteSource string
UseCLISource bool
UseENVSource bool
UseMemSource bool
}
//Option is a func
type Option func(options *Options)
//WithRequiredFiles tell archaius to manage files, if not exist will return error
func WithRequiredFiles(f []string) Option {
return func(options *Options) {
options.RequiredFiles = f
}
}
//WithOptionalFiles tell archaius to manage files, if not exist will NOT return error
func WithOptionalFiles(f []string) Option {
return func(options *Options) {
options.OptionalFiles = f
}
}
//WithDefaultFileHandler let user custom handler
//you can decide how to convert file into kv pairs
func WithDefaultFileHandler(handler util.FileHandler) Option {
return func(options *Options) {
options.FileHandler = handler
}
}
//WithRemoteSource accept the information for initiating a remote source
func WithRemoteSource(provider string, ri *RemoteInfo) Option {
return func(options *Options) {
options.RemoteInfo = ri
options.RemoteSource = provider
}
}
//WithCommandLineSource enable cmd line source
//archaius will read command line params as key value
func WithCommandLineSource() Option {
return func(options *Options) {
options.UseCLISource = true
}
}
//WithENVSource enable env source
//archaius will read ENV as key value
func WithENVSource() Option {
return func(options *Options) {
options.UseENVSource = true
}
}
//WithMemorySource accept the information for initiating a Memory source
func WithMemorySource() Option {
return func(options *Options) {
options.UseMemSource = true
}
}
//FileOptions for AddFile func
type FileOptions struct {
Handler util.FileHandler
}
//FileOption is a func
type FileOption func(options *FileOptions)
//WithFileHandler use custom handler
func WithFileHandler(h util.FileHandler) FileOption {
return func(options *FileOptions) {
options.Handler = h
}
}