-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.go
71 lines (60 loc) · 1.65 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"io/ioutil"
"os"
yaml "gopkg.in/yaml.v2"
)
type config struct {
ServiceFiles []string `yaml:"service_files"`
Address string `yaml:"address"`
Proto string `yaml:"proto"`
UserAgent string `yaml:"user_agent"`
Workers int `yaml:"workers"`
Timeout int `yaml:"timeout"`
NoProgress bool `yaml:"no_progress"`
NoBashComments bool `yaml:"no_bash_comments"`
Output string `yaml:"output"`
services map[string]service `yaml:"services"`
}
type service struct {
Addresses []string `yaml:"addresses"`
Tests map[string]test `yaml:"tests"`
}
type test struct {
SSL bool `yaml:"ssl"`
Status int `yaml:"status"`
Resources map[string]resource `yaml:"resources"`
RequestHeaders map[string]string `yaml:"req_headers"`
ExpectedHeaders map[string][]string `yaml:"expected_headers"`
}
type resource struct {
URL string `yaml:"url"`
ContentType string `yaml:"content_type"`
Contains []string `yaml:"contains"`
}
func (c *config) ReadServiceFiles() error {
s := map[string]service{}
for _, file := range c.ServiceFiles {
fi, err := os.Stat(file)
if err != nil {
return err
}
mode := fi.Mode()
if mode.IsDir() {
continue
}
yamlFile, err := ioutil.ReadFile(file)
if err != nil {
errOut := fmt.Errorf("error while reading config file %s: %s", file, err)
return errOut
}
err = yaml.Unmarshal(yamlFile, s)
if err != nil {
errOut := fmt.Errorf("error while unmarshalling config file %s: %s", file, err)
return errOut
}
}
c.services = s
return nil
}