diff options
author | jan <jan@ruken.pw> | 2015-12-21 21:17:18 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2015-12-21 21:17:18 (UTC) |
commit | c3e905c2698f6eb44e291eeb6b180b13755b7705 (patch) | |
tree | 5307f8c0f049ff4d2197deac6d618198a2751aa3 /config.go | |
parent | d55a93e653ff5d8810d539724c3d5a9ad96b8453 (diff) |
grilist als extra-package erstellt damit wir es sharen können mit modulen. Module hinzugefügt, jetzt brauchen wir langsam mal die ganzen grils
Diffstat (limited to 'config.go')
-rw-r--r-- | config.go | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/config.go b/config.go deleted file mode 100644 index b7149a6..0000000 --- a/config.go +++ /dev/null | |||
@@ -1,63 +0,0 @@ | |||
1 | package main | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "log" | ||
6 | "os" | ||
7 | |||
8 | "github.com/BurntSushi/toml" | ||
9 | ) | ||
10 | |||
11 | type Config struct { | ||
12 | Database struct { | ||
13 | Hostname string `toml:"hostname"` | ||
14 | //Port int `toml:"port"` | ||
15 | Database string `toml:"database"` | ||
16 | User string `toml:"user"` | ||
17 | Password string `toml:"password"` | ||
18 | SSLEnabled bool `toml:ssl_enabled"` | ||
19 | } `toml:"database"` | ||
20 | } | ||
21 | |||
22 | func (c *Config) DBConnectionString() string { | ||
23 | var sslmode string | ||
24 | if c.Database.SSLEnabled { | ||
25 | sslmode = "require" | ||
26 | } else { | ||
27 | sslmode = "disable" | ||
28 | } | ||
29 | return fmt.Sprintf("host=%s user=%s dbname=%s password=%s sslmode=%s", | ||
30 | c.Database.Hostname, | ||
31 | c.Database.User, | ||
32 | c.Database.Database, | ||
33 | c.Database.Password, | ||
34 | sslmode) | ||
35 | } | ||
36 | |||
37 | func LoadConfig() Config { | ||
38 | var config Config | ||
39 | var path string | ||
40 | log.Println("Loading config...") | ||
41 | for _, v := range []string{ | ||
42 | "grilist.conf", | ||
43 | "~/grilist.conf", | ||
44 | "/etc/grilist.conf", | ||
45 | } { | ||
46 | log.Printf("Try \"%s\"...", v) | ||
47 | if _, err := os.Stat(v); err != nil { | ||
48 | log.Printf("Loading config at \"%s\" failed!", v) | ||
49 | } else { | ||
50 | log.Printf("Config file found!") | ||
51 | path = v | ||
52 | break | ||
53 | } | ||
54 | } | ||
55 | if path == "" { | ||
56 | log.Fatal("No config file found at the possible locations!") | ||
57 | } | ||
58 | if _, err := toml.DecodeFile(path, &config); err != nil { | ||
59 | log.Printf("%v", err) | ||
60 | log.Fatal("Fatal error while reading the config!") | ||
61 | } | ||
62 | return config | ||
63 | } | ||