Skip to content
Snippets Groups Projects
Commit 180f0156 authored by Martin Stiemerling's avatar Martin Stiemerling
Browse files

some clean-up

parent 006aaa1b
Branches
Tags
1 merge request!16some clean-up
Pipeline #52003 passed
package nucleus
import (
"fmt"
"github.com/openconfig/ygot/ygot"
"net"
yangPro "gosdn/yang-processor"
)
// This is a test function in order to see how to generate JSON encoded openconfig stuff
func AssembleJSON() {
// Build my device
d := &yangPro.Device{}
interfaces, _ := net.Interfaces()
for _, iface := range interfaces {
fmt.Println(iface.Name)
i, err := d.NewInterface(iface.Name)
if err != nil {
panic(err)
}
i.Mtu = ygot.Uint16(234)
//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))
}
fmt.Println(json)
// 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))
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment