blasphem/pkg/config/read.go
2022-09-26 15:00:21 -04:00

39 lines
529 B
Go

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
}