aboutsummaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorAdam Mathes <adam@trenchant.org>2018-07-07 10:39:09 -0700
committerAdam Mathes <adam@trenchant.org>2018-07-07 10:39:09 -0700
commite319e1062d62ce2f5965f191e0e30802b0bd97fd (patch)
tree4224a4bc7cd6c5f0e7c0fa2cd259923beec71a58 /config
parent51ccece9ca6f60ec2debc7af392ba8da004a21dd (diff)
downloadneko-e319e1062d62ce2f5965f191e0e30802b0bd97fd.tar.gz
neko-e319e1062d62ce2f5965f191e0e30802b0bd97fd.tar.bz2
neko-e319e1062d62ce2f5965f191e0e30802b0bd97fd.zip
yaml config file, cmd line overrides
Diffstat (limited to 'config')
-rw-r--r--config/config.go35
1 files changed, 27 insertions, 8 deletions
diff --git a/config/config.go b/config/config.go
index 91ffd87..f9dd386 100644
--- a/config/config.go
+++ b/config/config.go
@@ -1,28 +1,47 @@
package config
import (
- "encoding/json"
+ "gopkg.in/yaml.v2"
"io/ioutil"
"log"
)
type Settings struct {
- DBFile string `json:"db"`
- Port int `json:"web"`
- Username string `json:"username"`
- DigestPassword string `json:"password"`
- ProxyImages bool `json:"proxy_images"`
+ DBFile string `yaml:"database"`
+ Port int `yaml:"http"`
+ DigestPassword string `yaml:"password"`
+ CrawlMinutes int `yaml:"minutes"`
+ ProxyImages bool `yaml:"imageproxy"`
}
var Config Settings
-func Read(filename string) {
+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 = json.Unmarshal(file, &Config)
+ 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
+ }
+}