-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
48 lines (40 loc) · 909 Bytes
/
config.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
package vwap_service
import (
"gopkg.in/yaml.v3"
"io/ioutil"
"log"
)
type CoinbaseConf struct {
WebsocketsUrl string `yaml:"websockets_url"`
Channels []string `yaml:"channels"`
}
type VWAPConf struct {
DataPoints int `yaml:"data_points"`
}
type Config struct {
Coinbase CoinbaseConf `yaml:"coinbase"`
VWAP VWAPConf `yaml:"vwap"`
}
func NewDefaultConfig() *Config {
return &Config{
Coinbase: CoinbaseConf{
WebsocketsUrl: "wss://ws-feed.pro.coinbase.com",
Channels: []string {
"BTC-USD", "ETH-USD", "ETH-BTC",
},
},
VWAP: VWAPConf{
DataPoints: 200,
},
}
}
func (c *Config) Load(file string) {
buf, err := ioutil.ReadFile(file)
if err != nil {
log.Printf("error loading config using the default: [%s]", err.Error())
return
}
if err := yaml.Unmarshal(buf, c); err != nil {
log.Printf("error unmarshalling yaml using the default: [%s]", err.Error())
}
}