-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfig.go
55 lines (41 loc) · 1.04 KB
/
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
48
49
50
51
52
53
54
55
package main
import (
"log"
"os"
"path/filepath"
yamljson "github.com/ghodss/yaml"
)
type RelatedFile struct {
File string `json:"file"`
LoadInto string `json:"load_into"`
ContentKey string `json:"content_key"`
Set map[string]interface{} `json:"set"`
}
type Config struct {
// For any leaf file, consider those in same directory as related files:
RelatedFiles []string `json:"related_files"`
RelatedFilesV2 []RelatedFile `json:"related_files_v2"`
// Plumbing variable to know when config was loaded from disk.
initialized bool
}
func getConf(root string) Config {
c := Config{}
path := filepath.Join(root, ".agnosticv.yaml")
if !fileExists(path) {
return c
}
yamlFile, err := os.ReadFile(path)
if err != nil {
log.Fatalf("Can't read config file: #%v", err)
}
err = yamljson.Unmarshal(yamlFile, &c)
if err != nil {
log.Fatalf("Unmarshal: %v", err)
}
c.initialized = true
return c
}
var config Config
func initConf(root string) {
config = getConf(root)
}