-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.go
51 lines (45 loc) · 982 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
49
50
51
/*
* Copyright (C) 2018 Aurélien Chabot <[email protected]>
*
* SPDX-License-Identifier: MIT
*/
package main
import (
"io/ioutil"
"log"
)
import "github.com/go-yaml/yaml"
const defaultServerHost = "localhost"
const defaultServerPort = "9091"
const defaultUpdateInterval = 10
// Config is handling the config parsing
type Config struct {
Server struct {
Host string
Port string
}
UpdateInterval uint64 `yaml:"update_interval"`
Feeds []string
}
// NewConfig return a new Config object
func NewConfig(filename string) *Config {
var config Config
source, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatal(err)
}
err = yaml.Unmarshal(source, &config)
if err != nil {
log.Fatal(err)
}
if config.Server.Host == "" {
config.Server.Host = defaultServerHost
}
if config.Server.Port == "" {
config.Server.Port = defaultServerPort
}
if config.UpdateInterval == 0 {
config.UpdateInterval = defaultUpdateInterval
}
return &config
}