slimming/config.go
2022-08-25 15:31:51 +08:00

37 lines
500 B
Go

package main
import (
"log"
"os"
"gopkg.in/yaml.v3"
)
type Node struct {
Real string `yaml:"real"`
Virt string `yaml:"virt"`
}
type Config struct {
Network struct {
Self Node `yaml:"self"`
Nodes []Node `yaml:"nodes"`
} `yaml:"network"`
}
var config = NewConfig()
func NewConfig() *Config {
cnf := &Config{}
f, err := os.Open("config.yaml")
if err != nil {
log.Panic(err)
}
dec := yaml.NewDecoder(f)
err = dec.Decode(cnf)
if err != nil {
log.Panic(err)
}
return cnf
}