-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
46 lines (41 loc) · 1005 Bytes
/
config.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
package pixelcheck
import (
"log"
"os"
"gopkg.in/yaml.v2"
)
type Config struct {
DBConn string `yaml:"connstring"`
URL string `yaml:"url"`
Listen string `yaml:"listen"`
To string `yaml:"to"`
From string `yaml:"from"`
Smarthost string `yaml:"smarthost"`
Username string `yaml:"username"`
Password string `yaml:"password"`
Templates string `yaml:"template_dir"`
Cert string `yaml:"tlscert"`
Key string `yaml:"tlskey"`
Image string `yaml:"image"`
ImageDir string `yaml:"image_dir"`
}
func New(filename string) Config {
c := Config{
Listen: ":8080",
Templates: ".",
ImageDir: ".",
Image: "default.png",
}
c.Load(filename)
return c
}
func (c *Config) Load(filename string) {
f, err := os.Open(filename)
if err != nil {
log.Fatalf("Failed to open configuration file %s: %s", filename, err)
}
err = yaml.NewDecoder(f).Decode(c)
if err != nil {
log.Fatalf("Failed to parse configuration file %s: %s", filename, err)
}
}