/
load_config.go
60 lines (50 loc) · 1.22 KB
/
load_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
56
57
58
59
60
package config
import (
"fmt"
"os"
"gopkg.in/yaml.v2"
)
func LoadConfig(configPath string) (*Config, error) {
config := &Config{}
file, err := os.Open(configPath)
if err != nil {
return nil, err
}
defer file.Close()
d := yaml.NewDecoder(file)
if err := d.Decode(&config); err != nil {
_, err := LoadDeprecatedConfig(configPath)
if err == nil {
return nil, fmt.Errorf("A deprecated architecture description was provided. To update the arch-go.yml file please run 'arch-go migrate-config'")
}
return nil, err
}
checkThreshold(config)
checkForDeprecatedConfiguration(config)
return config, nil
}
func checkThreshold(config *Config) {
if config.Threshold == nil {
config.Threshold = &Threshold{}
}
maxThreshold := 100
if config.Threshold.Compliance == nil {
config.Threshold.Compliance = &maxThreshold
}
if config.Threshold.Coverage == nil {
config.Threshold.Coverage = &maxThreshold
}
}
func LoadDeprecatedConfig(configPath string) (*DeprecatedConfig, error) {
config := &DeprecatedConfig{}
file, err := os.Open(configPath)
if err != nil {
return nil, err
}
defer file.Close()
d := yaml.NewDecoder(file)
if err := d.Decode(&config); err != nil {
return nil, err
}
return config, nil
}