aboutsummaryrefslogtreecommitdiff
path: root/config/config.go
blob: 19a79c442dc3d9dcec715c0811f8796fa8829d0a (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
36
// 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"`
	DefaultRepository string   `yaml:"DefaultRepository"`
	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)
}