blasphem/pkg/config/read.go

41 lines
620 B
Go
Raw Normal View History

2022-09-25 11:42:36 -04:00
package config
import (
"io"
"os"
"path"
"dynatron.me/x/blasphem/internal/common"
"gopkg.in/yaml.v3"
)
func ReadConfig() (*Config, error) {
2022-10-25 00:16:29 -04:00
// TODO: make this use an arg or an env, and unify with pkg/storage/'s home determination
2022-09-25 11:42:36 -04:00
cfg := &Config{}
home, err := os.UserHomeDir()
if err != nil {
return nil, err
}
2022-09-26 15:00:21 -04:00
cfgPath := path.Join(home, "/."+common.AppName, "/config.yaml")
2022-09-25 11:42:36 -04:00
r, err := os.Open(cfgPath)
if err != nil {
return nil, err
}
cfgB, err := io.ReadAll(r)
if err != nil {
return nil, err
}
err = yaml.Unmarshal(cfgB, cfg)
if err != nil {
return nil, err
}
return cfg, nil
}