-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.go
65 lines (55 loc) · 1.29 KB
/
settings.go
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"encoding/json"
"fmt"
"log"
"os"
)
type Settings struct {
Logging struct {
Debug bool
} `json:"Logging"`
ConnectionString string
RabbitMQ struct {
ConnectionString string `json:"ConnectionString"`
ChannelName string `json:"ChannelName"`
Bindings []Binding `json:"Bindings"`
} `json:"RabbitMQ"`
}
func (s Settings) String() string {
bytes, err := json.MarshalIndent(s, "", "\t")
if err != nil {
panic(fmt.Sprintln("Unable to json marshal Settings:", err))
}
return string(bytes)
}
type Binding struct {
Exchange string `json:"Exchange"`
Topic string `json:"Topic"`
}
func LoadSettings() (s Settings) {
s.SetDefaults()
file, err := os.Open("appsettings.json")
if err != nil {
log.Printf("Error reading config file: %s \n Progressing without it.", err)
return
}
dec := json.NewDecoder(file)
err = dec.Decode(&s)
if err != nil {
log.Fatalf("Error parsing config file: %s \n", err)
}
return
}
func (s *Settings) SetDefaults() {
s.Logging.Debug = false
s.ConnectionString = "user=postgres password=password dbname=rabbithole sslmode=verify-full"
s.RabbitMQ.ConnectionString = "amqp://localhost/"
s.RabbitMQ.ChannelName = "rabbithole"
s.RabbitMQ.Bindings = []Binding{
{
Exchange: "demo",
Topic: "#",
},
}
}