mkvm/config/config.go

39 lines
697 B
Go
Raw Normal View History

2024-12-03 04:22:30 +00:00
package config
2024-12-03 06:57:21 +00:00
import (
"io"
"os"
"path/filepath"
"gopkg.in/yaml.v2"
"git.janky.solutions/finn/conflib"
)
2024-12-03 04:22:30 +00:00
type Config struct {
2024-12-03 06:57:21 +00:00
StoragePool string `default:"default" yaml:"storage_pool"`
Network string `yaml:"network"`
Bridge string `yaml:"bridge"`
}
var C Config
func Load() (err error) {
loader := conflib.Loader[Config]{AllowNoSources: true}
C, err = loader.Load(filepath.Join(os.Getenv("HOME"), ".config", "mkvm.yaml"))
if err != nil {
return err
}
if C.Network == "" && C.Bridge == "" {
C.Network = "default"
}
return nil
2024-12-03 04:22:30 +00:00
}
2024-12-03 06:57:21 +00:00
func init() {
conflib.RegisterParser(".yaml", func(target any, f io.Reader) error { return yaml.NewDecoder(f).Decode(target) })
2024-12-03 04:22:30 +00:00
}