-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.go
51 lines (38 loc) · 877 Bytes
/
data.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
package main
import (
"encoding/json"
"errors"
"os"
"path"
)
func GetData(path string) map[string]map[string]any {
data := make(map[string]map[string]any)
file, err := os.Open(path)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
check(err)
}
logger.Debugf("No data found (%v)", path)
return data
}
defer file.Close()
logger.Debugf("Found data (%v)", path)
decoder := json.NewDecoder(file)
err = decoder.Decode(&data)
check(err)
return data
}
func BuildData(config *buildConfig, path_ string) map[string]any {
data := make(map[string]any)
for key, value := range config.Data["default"] {
data[key] = value
}
for key, value := range config.Data[config.TemplateName] {
data[key] = value
}
dataPath := path.Join(config.TemplateName, path_)
for key, value := range config.Data[dataPath] {
data[key] = value
}
return data
}