-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
49 lines (45 loc) · 1.09 KB
/
types.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
package main
import (
"fmt"
"io/ioutil"
"os"
"gopkg.in/yaml.v2"
)
type Config struct {
Hosts []struct {
HostName string `yaml:"name"`
Connection string `yaml:"connection"`
UserName string `yaml:"username"`
PassWord string `yaml:"password"`
Commands []struct {
Name string `yaml:"name"`
String string `yaml:"string"`
UserInput bool `yaml:"userinput"`
WhiteSpace bool `yaml:"whitespace"`
} `yaml:"commands"`
} `yaml:"hosts"`
}
func GetConfig() {
if _, err := os.Stat("./config/config.yml"); err == nil { // check if config file exists
yamlFile, err := ioutil.ReadFile("./config/config.yml")
if err != nil {
panic(err)
}
err = yaml.Unmarshal(yamlFile, &config)
if err != nil {
panic(err)
}
} else if os.IsNotExist(err) { // config file not included, use embedded config
yamlFile, err := Asset("config/config.yml")
if err != nil {
panic(err)
}
err = yaml.Unmarshal(yamlFile, &config)
if err != nil {
panic(err)
}
} else {
fmt.Println("Schrodinger: file may or may not exist. See err for details.")
// panic(err)
}
}