blob: 03b3d3399e16676d50bff4bc1fb7d8e5d9f12465 (
plain)
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
|
package conf
import (
"log"
"os"
"github.com/BurntSushi/toml"
)
type (
Conf struct {
Db Db
Server Server
}
Db struct {
Adapter string `toml:"DB_ADAPTER"`
User string `toml:"DB_USER"`
Password string `toml:"DB_PASS"`
}
Server struct {
Hostname string `toml:"SERVER_HOSTNAME"`
Port string `toml:"SERVER_PORT"`
}
)
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.Db.Adapter)
return &c
}
|