-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigFile.go
More file actions
49 lines (40 loc) · 1015 Bytes
/
configFile.go
File metadata and controls
49 lines (40 loc) · 1015 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
package main
import (
"io/ioutil"
yaml "gopkg.in/yaml.v2"
)
// type yaml struct {
// }
// func (u *yaml) Unmarshal(in []byte, out interface{}) (error) {
// return yamlV2.Unmarshal(in, out)
// }
type ConfigCredentials struct {
Email string `yaml:"email"`
Password string `yaml:"password"`
}
type ConfigUser struct {
Credentials ConfigCredentials `yaml:"credentials"`
LoginUrl string `yaml:"login_url"`
}
type ConfigFileStruct struct {
User ConfigUser `yaml:"user"`
}
func readConfigFile(fPath string) ([]byte, LocalError) {
data, err := ioutil.ReadFile(fPath)
if err != nil {
return nil, ConfigFileReadErr.WithError(err)
}
return data, nil
}
func LoadConfigFile() (ConfigFileStruct, LocalError) {
data, lErr := readConfigFile("./config.yaml")
if lErr != nil {
return ConfigFileStruct{}, lErr
}
output := ConfigFileStruct{}
err := yaml.Unmarshal(data, &output)
if err != nil {
return ConfigFileStruct{}, ConfigFileUnmarshalErr.WithError(err)
}
return output, nil
}