mirror of
https://codeberg.org/lauralani/ipam.git
synced 2024-11-30 14:50:37 +01:00
41 lines
612 B
Go
41 lines
612 B
Go
|
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)
|
||
|
}
|