-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
59 lines (47 loc) · 1.13 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
package internal
import (
"github.com/zgwit/iot-master/v3/pkg/config"
"github.com/zgwit/iot-master/v3/pkg/env"
)
type Options struct {
Id string `json:"id"`
Secret string `json:"secret"`
Sign string `json:"sign"`
Template string `json:"template"`
}
func Default() Options {
return Options{}
}
var options Options = Default()
var configure = config.AppName() + ".aliyun.yaml"
const ENV = "IOT_MASTER_ALIYUN_"
func GetOptions() Options {
return options
}
func SetOptions(opts Options) {
options = opts
}
func init() {
options.FromEnv()
}
func (options *Options) FromEnv() {
options.Id = env.Get(ENV+"ID", options.Id)
options.Secret = env.Get(ENV+"SECRET", options.Secret)
options.Sign = env.Get(ENV+"SIGN", options.Sign)
options.Template = env.Get(ENV+"TEMPLATE", options.Template)
}
func (options *Options) ToEnv() []string {
ret := []string{
ENV + "ID=" + options.Id,
ENV + "SECRET=" + options.Secret,
ENV + "SIGN=" + options.Sign,
ENV + "TEMPLATE=" + options.Template,
}
return ret
}
func Load() error {
return config.Load(configure, &options)
}
func Store() error {
return config.Store(configure, &options)
}