-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
47 lines (38 loc) · 798 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
47
package selfwatch
import (
"encoding/json"
"log"
"os"
)
const DefaultConfigFname = "~/.selfwatch/config.json"
type config struct {
DbName string
RemoteUrl string
RemoteFlushDelay float64
SyncDelay float64
NewDayHour int
}
var defaultConfig = config{
DbName: "~/.selfwatch/selfwatch.db",
RemoteUrl: "",
RemoteFlushDelay: 60,
SyncDelay: 60,
NewDayHour: 4,
}
func LoadConfig(fname string) *config {
c := defaultConfig
if fname == "" {
return &c
}
log.Print("Loading config ", fname)
jsonBlob, err := os.ReadFile(fname)
if err == nil {
err = json.Unmarshal(jsonBlob, &c)
if err != nil {
log.Fatal("Failed parsing config: ", fname, ": ", err.Error())
}
} else {
log.Print(err.Error())
}
return &c
}