-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
50 lines (40 loc) · 769 Bytes
/
config.go
File metadata and controls
50 lines (40 loc) · 769 Bytes
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
package main
import (
"encoding/json"
"os"
"path/filepath"
)
type config struct {
AlwaysExclude []string `json:"alwaysExclude"`
}
func defaultConfig() config {
return config{
AlwaysExclude: []string{".git"},
}
}
func configPath() string {
home, err := os.UserHomeDir()
if err != nil {
return ""
}
return filepath.Join(home, ".local", "share", "trueblocks", "differ", "config.json")
}
func loadConfig() config {
cfg := defaultConfig()
path := configPath()
if path == "" {
return cfg
}
data, err := os.ReadFile(path)
if err != nil {
return cfg
}
var fileCfg config
if err := json.Unmarshal(data, &fileCfg); err != nil {
return cfg
}
if len(fileCfg.AlwaysExclude) > 0 {
cfg.AlwaysExclude = fileCfg.AlwaysExclude
}
return cfg
}