package conf import ( "log" "os" "github.com/BurntSushi/toml" ) type ( Conf struct { Db Db `toml:"database"` Server Server `toml:"server"` } Db struct { Adapter string `toml:"adapter"` User string `toml:"user"` Password string `toml:"pass"` } Server struct { Hostname string `toml:"hostname"` Port string `toml:"port"` TemplatePath string `toml:"template_path"` } ) func NewConf() *Conf { workingdir, err := os.Getwd() if err != nil { log.Fatal(err) } filepath := os.Getenv("NEWSSTAND_CONFIG_PATH") if filepath == "" { filepath = workingdir + "/.newsstandrc.toml" } log.Printf("Config file path: %s", filepath) c := Conf{ Db{}, Server{ TemplatePath: workingdir + "/views", }, } _, err = toml.DecodeFile(filepath, &c) if err != nil { log.Fatalln(err) } log.Printf("Config loaded: %s", c) return &c }