-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
56 lines (45 loc) · 982 Bytes
/
main.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
package config
import (
"errors"
"os"
"path/filepath"
"github.com/safing/portbase/dataroot"
"github.com/safing/portbase/modules"
"github.com/safing/portbase/utils"
)
const (
configChangeEvent = "config change"
)
var (
module *modules.Module
dataRoot *utils.DirStructure
)
// SetDataRoot sets the data root from which the updates module derives its paths.
func SetDataRoot(root *utils.DirStructure) {
if dataRoot == nil {
dataRoot = root
}
}
func init() {
module = modules.Register("config", prep, start, nil, "database")
module.RegisterEvent(configChangeEvent)
}
func prep() error {
SetDataRoot(dataroot.Root())
if dataRoot == nil {
return errors.New("data root is not set")
}
return nil
}
func start() error {
configFilePath = filepath.Join(dataRoot.Path, "config.json")
err := registerAsDatabase()
if err != nil && !os.IsNotExist(err) {
return err
}
err = loadConfig()
if err != nil && !os.IsNotExist(err) {
return err
}
return nil
}