39 lines
531 B
Go
39 lines
531 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
|
|
}
|