ipam/test/test_yaml.go

41 lines
612 B
Go
Raw Normal View History

2023-03-12 16:58:30 +01:00
package main
import (
"fmt"
"io/ioutil"
"gopkg.in/yaml.v3"
)
type Address struct {
Fqdn string `yaml:"fqdn"`
}
type SubnetFile struct {
Name string `yaml:"name"`
Vlan string `yaml:"vlan"`
Addresses []Address `yaml:"addresses"`
}
func main() {
// Read the file
data, err := ioutil.ReadFile("subnet.yaml")
if err != nil {
fmt.Println(err)
return
}
// Create a struct to hold the YAML data
var asd SubnetFile
// Unmarshal the YAML data into the struct
err = yaml.Unmarshal(data, &asd)
if err != nil {
fmt.Println(err)
return
}
// Print the data
fmt.Println(asd)
}