I'm trying to set up a RESTCONF client through FREECONF. I'm working through the Car example and aim to present the user with configuration, update the configuration, and display the new configuration. Unfortunately, after a configuration update I fail to display the full configuration again.
// Courtesy to https://freeconf.org/docs/examples/restconf-client/
package main
import (
"github.com/freeconf/restconf"
"github.com/freeconf/restconf/client"
"github.com/freeconf/yang/nodeutil"
)
func connectClient() {
// YANG: just need YANG file ietf-yang-library.yang, not the yang of remote system as that will
// be downloaded as needed
ypath := restconf.InternalYPath
// Connect
proto := client.ProtocolHandler(ypath)
dev, err := proto("http://localhost:8080/restconf")
if err != nil {
panic(err)
}
// Get a browser to walk server's management API for car
car, err := dev.Browser("car")
if err != nil {
panic(err)
}
root := car.Root()
defer root.Release()
actual, err := nodeutil.WritePrettyJSON(car.Root())
if err != nil {
panic(err)
}
println("========== initial config ==========")
println(actual)
n, err := nodeutil.ReadJSON(`{"speed":50}`)
if err != nil {
panic(err)
}
err = root.UpsertFrom(n)
if err != nil {
panic(err)
}
actual, err = nodeutil.WritePrettyJSON(car.Root())
if err != nil {
panic(err)
}
println("========== config after setting speed ==========")
println(actual)
n, err = nodeutil.ReadJSON(`{"pollInterval":50}`)
if err != nil {
panic(err)
}
err = root.UpsertFrom(n)
if err != nil {
panic(err)
}
actual, err = nodeutil.WritePrettyJSON(car.Root())
if err != nil {
panic(err)
}
println("========== config after setting pollInterval ==========")
println(actual)
}
func main() {
connectClient()
}
========== initial config ==========
{
"speed":50,
"pollInterval":50,
"running":false,
"miles":0,
"lastRotation":0,
"tire":[
{
"pos":0,
"size":"H15",
"worn":false,
"wear":100,
"flat":false},
{
"pos":1,
"size":"H15",
"worn":false,
"wear":100,
"flat":false},
{
"pos":2,
"size":"H15",
"worn":false,
"wear":100,
"flat":false},
{
"pos":3,
"size":"H15",
"worn":false,
"wear":100,
"flat":false}]}
========== config after setting speed ==========
{
"speed":50,
"tire":[
{
"size":"H15"},
{
"size":"H15"},
{
"size":"H15"},
{
"size":"H15"}]}
========== config after setting pollInterval ==========
{
"pollInterval":50,
"tire":[
{
"size":"H15"},
{
"size":"H15"},
{
"size":"H15"},
{
"size":"H15"}]}
Could you help me out? Looking forward to your (usually impressively swift) reply!