diff options
Diffstat (limited to 'conf/conf.go')
| -rw-r--r-- | conf/conf.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/conf/conf.go b/conf/conf.go new file mode 100644 index 0000000..b9dadcd --- /dev/null +++ b/conf/conf.go @@ -0,0 +1,34 @@ +package conf + +import ( + "log" + "os" + "github.com/BurntSushi/toml" +) + +type Conf struct { + DbAdapter string `toml:"DB_ADAPTER"` + DbUser string `toml:"DB_USER"` + DbPassword string `toml:"DB_PASS"` +} + +func Load() *Conf { + filepath := os.Getenv("NEWSSTAND_CONFIG_PATH") + if filepath == "" { + workingdir, err := os.Getwd() + if err != nil { + log.Fatal(err) + } + filepath = workingdir + "/.newsstandrc.toml" + } + log.Printf("Config file path: %s", filepath) + + var c Conf + _, err := toml.DecodeFile(filepath, &c) + if err != nil { + log.Fatalln(err) + } + log.Println(c) + + return &c +} |
