refactor(ops/besadii): Get config from home directory by default
Slightly more ergonomic in some setups. Change-Id: I565f2d242852ffd299ef5d5740a47520187dd4b4
This commit is contained in:
parent
dcb2410982
commit
b679bb4034
1 changed files with 16 additions and 1 deletions
|
@ -23,6 +23,7 @@ import (
|
|||
"log/syslog"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/user"
|
||||
"path"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
@ -96,10 +97,24 @@ type reviewInput struct {
|
|||
Tag string `json:"tag"`
|
||||
}
|
||||
|
||||
func defaultConfigLocation() (string, error) {
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get current user: %w", err)
|
||||
}
|
||||
|
||||
return path.Join(usr.HomeDir, "besadii.json"), nil
|
||||
}
|
||||
|
||||
func loadConfig() (*config, error) {
|
||||
configPath := os.Getenv("BESADII_CONFIG")
|
||||
|
||||
if configPath == "" {
|
||||
configPath = "/etc/besadii/config.json"
|
||||
var err error
|
||||
configPath, err = defaultConfigLocation()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get config location: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
configJson, err := ioutil.ReadFile(configPath)
|
||||
|
|
Loading…
Reference in a new issue