blob: 5debdb65b57d22ef6143cdf17f815d40fda16def (
plain) (
blame)
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
|
// Used to define and load this application's specific configuration
package config
import (
"gopkg.in/yaml.v2"
"io/ioutil"
)
var (
defaultConfig string = "config.yml"
)
type Config struct {
SteamRepositories []string `yaml:"SteamRepositories"`
Listen string
}
// By default it reads 'config.yml' in the current directory
func LoadConfig() (*Config, error) {
c := &Config{}
err := c.ReadDefaultConfig()
return c, err
}
func (c *Config) ReadDefaultConfig() error {
return c.ReadConfig(defaultConfig)
}
func (c *Config) ReadConfig(cfg string) error {
contents, err := ioutil.ReadFile(cfg)
if err != nil {
return err
}
return yaml.Unmarshal([]byte(contents), c)
}
|