Newer
Older
yangPro "code.fbi.h-da.de/cocsn/yang-modules/generated/ciena"
"github.com/openconfig/ygot/ygot"
// This is a test function in order to see how to generate JSON encoded openconfig stuff
func AssembleJSON() {
// Build my device
interfaces, _ := net.Interfaces()
for _, iface := range interfaces {
fmt.Println(iface.Name)
i, err := d.WaveserverInterfaces.NewLogicalInterface("en0")
i.State = &yangPro.CienaWaveserverInterfaces_WaveserverInterfaces_LogicalInterface_State{
AdminState: 0,
OperationalState: 0,
}
//i.Mtu = ygot.Uint16(iface.MTU)
}
// EmitJSON from the ygot library directly does .Validate() and outputs JSON in
// the specified format.
json, err := ygot.EmitJSON(d, &ygot.EmitJSONConfig{
Format: ygot.RFC7951,
Indent: " ",
RFC7951Config: &ygot.RFC7951JSONConfig{
AppendModuleName: true,
},
})
if err != nil {
panic(fmt.Sprintf("JSON demo error: %v", err))
}
// and now try to read the data from it...
// Device struct to unmarshal into.
loadd := &yangPro.Device{}
if err := yangPro.Unmarshal([]byte(json), loadd); err != nil {
panic(fmt.Sprintf("Cannot unmarshal JSON: %v", err))
}