40 lines
620 B
Go
40 lines
620 B
Go
package config
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"path"
|
|
|
|
"dynatron.me/x/blasphem/internal/common"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
func ReadConfig() (*Config, error) {
|
|
// TODO: make this use an arg or an env, and unify with pkg/storage/'s home determination
|
|
cfg := &Config{}
|
|
|
|
home, err := os.UserHomeDir()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
cfgPath := path.Join(home, "/."+common.AppName, "/config.yaml")
|
|
|
|
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
|
|
}
|