38 lines
697 B
Go
38 lines
697 B
Go
package config
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
"git.janky.solutions/finn/conflib"
|
|
)
|
|
|
|
type Config struct {
|
|
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
|
|
}
|
|
|
|
func init() {
|
|
conflib.RegisterParser(".yaml", func(target any, f io.Reader) error { return yaml.NewDecoder(f).Decode(target) })
|
|
}
|