add lucy config.

This commit is contained in:
2021-09-24 17:12:27 +02:00
parent 3c2aa7212d
commit 9b9e5e9da8
3 changed files with 39 additions and 1 deletions
+31
View File
@@ -0,0 +1,31 @@
package main
import (
"gopkg.in/yaml.v2"
"os"
"path"
)
type Config struct {
Remote string `yaml:"remote"`
}
func loadConfig() (*Config, error) {
homedir, err := os.UserHomeDir()
if err != nil {
return nil, err
}
f, err := os.Open(path.Join(homedir, ".config/lucy.yaml"))
if err != nil {
return nil, err
}
cfg := Config{}
err = yaml.NewDecoder(f).Decode(&cfg)
if err != nil {
return nil, err
}
return &cfg, nil
}
+7 -1
View File
@@ -11,7 +11,13 @@ import (
)
func main() {
c := client.Client{APIRoot: "http://10.24.4.1:8000"}
cfg, err := loadConfig()
if err != nil {
log.Println("Config at $HOME/.config/lucy.yaml failed:", err)
cfg = &Config{Remote: "http://localhost:8000"}
}
c := client.Client{APIRoot: cfg.Remote}
cmd := parseCommand(os.Args[1:])
switch cmd.Name {