aboutsummaryrefslogtreecommitdiffstats
path: root/config/config.go
blob: f9dd3862aead1f3fd36477590078ad7859b49494 (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
37
38
39
40
41
42
43
44
45
46
47
package config

import (
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"log"
)

type Settings struct {
	DBFile         string `yaml:"database"`
	Port           int    `yaml:"http"`
	DigestPassword string `yaml:"password"`
	CrawlMinutes   int    `yaml:"minutes"`
	ProxyImages    bool   `yaml:"imageproxy"`
}

var Config Settings

func Init(filename string) {
	if filename != "" {
		readConfig(filename)
	}
	addDefaults()
}

func readConfig(filename string) {
	file, e := ioutil.ReadFile(filename)
	if e != nil {
		log.Fatal("Can not read config file\n", e)
	}
	e = yaml.Unmarshal(file, &Config)
	if e != nil {
		log.Fatal("Config read error\n", e)
	}
}

func addDefaults() {
	if Config.DBFile == "" {
		Config.DBFile = "neko.db"
	}
	if Config.Port == 0 {
		Config.Port = 4994
	}
	if Config.CrawlMinutes == 0 {
		Config.CrawlMinutes = 60
	}
}