blob: e7a152a668580177a3b2e7aa7ba8029ef1aa5c8d (
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
49
50
51
52
53
54
55
56
57
58
|
package internal
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
)
type config struct {
EmailTo string
EmailFrom string
SMTPServer string `json:"SMTPServer,omitempty"`
StateDir string `json:"StateDir,omitempty"`
CheckTimeoutS int
CheckConcurrency int
Checks map[string]check
}
func newConfig(configFile string) (config, error) {
var config config
// Open the file
file, err := os.Open(configFile)
if err != nil {
return config, err
}
defer file.Close()
// Read the file content
bytes, err := ioutil.ReadAll(file)
if err != nil {
return config, err
}
// Parse the JSON content
err = json.Unmarshal(bytes, &config)
if err != nil {
return config, err
}
if config.SMTPServer == "" {
hostname, err := os.Hostname()
if err != nil {
panic(err)
}
config.SMTPServer = fmt.Sprintf("%s:25", hostname)
log.Println("Set SMTPServer to " + config.SMTPServer)
}
if config.StateDir == "" {
config.StateDir = "."
log.Println("Set StateDir to " + config.StateDir)
}
return config, nil
}
|