/
config.go
41 lines (31 loc) · 913 Bytes
/
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
package main
import (
"fmt"
"github.com/BurntSushi/toml"
)
type Config struct {
ListenAddress string `toml:"listen"`
StashHost string `toml:"stash_host"`
StashUser string `toml:"stash_user"`
StashPassword string `toml:"stash_password"`
LintArgs []string `toml:"lint_args"`
}
func getConfig(path string) (Config, error) {
config := Config{}
_, err := toml.DecodeFile(path, &config)
if err != nil {
return config, err
}
validationEmptyError := "`%s` value can't be empty"
switch "" {
case config.ListenAddress:
return config, fmt.Errorf(validationEmptyError, "listen")
case config.StashHost:
return config, fmt.Errorf(validationEmptyError, "stash_host")
case config.StashUser:
return config, fmt.Errorf(validationEmptyError, "stash_user")
case config.StashPassword:
return config, fmt.Errorf(validationEmptyError, "stash_password")
}
return config, nil
}