Newer
Older
"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)
}
// 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))
}