-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefaults.go
More file actions
61 lines (53 loc) · 1.38 KB
/
defaults.go
File metadata and controls
61 lines (53 loc) · 1.38 KB
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
package offchain
import (
"bytes"
_ "embed"
"io"
"github.com/ilyakaznacheev/cleanenv"
)
//go:embed defaults.yaml
var defaultsYAML string
func init() {
type configsection struct {
Offchain Config `yaml:"offchain"`
}
section := configsection{}
cleanenv.ParseYAML(io.Reader(bytes.NewBufferString(defaultsYAML)), §ion)
err := section.Offchain.Init()
if err != nil {
panic(err)
}
for _, exchage := range ValidExchangeIds {
defaultConfigs[exchage] = &ExchangeClientConfig{}
}
// set account types for each exchange
for _, exchange := range section.Offchain.Exchanges {
// set account types for each exchange
defaultConfigs[exchange.ExchangeId] = &exchange.ExchangeClientConfig
}
}
var defaultConfigs = map[ExchangeId]*ExchangeClientConfig{}
func ApplyDefaults(cfg *ExchangeConfig) {
def := defaultConfigs[cfg.ExchangeId]
// copy over account types if defined
if len(cfg.AccountTypes) == 0 {
cfg.AccountTypes = make([]*AccountTypeConfig, len(def.AccountTypes))
for i, at := range def.AccountTypes {
cpy := *at
cfg.AccountTypes[i] = &cpy
}
}
if cfg.NoAccountTypes == nil {
if def.NoAccountTypes != nil {
cpy := *def.NoAccountTypes
cfg.NoAccountTypes = &cpy
}
}
}
func GetDefaultConfig(exchangeId ExchangeId) (ExchangeClientConfig, bool) {
cfg, ok := defaultConfigs[exchangeId]
if !ok {
return ExchangeClientConfig{}, false
}
return *cfg, true
}