Skip to content
Snippets Groups Projects
Commit 7146ba9a authored by Martin Stiemerling's avatar Martin Stiemerling :speech_balloon:
Browse files

Merge branch 'some-fixes' into 'master'

some clean-up

See merge request cocsn/gosdn!16
parents 006aaa1b 180f0156
Branches
Tags v2.6.0
1 merge request!16some clean-up
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