blasphem/pkg/config/read.go

40 lines
531 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) {
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
}