Capabilities
The below snippet shows how to create a target, send a Capabilities Request and print the response.
package main
import (
"context"
"fmt"
"log"
"github.com/openconfig/gnmic/pkg/api"
"google.golang.org/protobuf/encoding/prototext"
)
func main() {
// create a target
tg, err := api.NewTarget(
api.Name("srl1"),
api.Address("10.0.0.1:57400"),
api.Username("admin"),
api.Password("admin"),
api.SkipVerify(true),
)
if err != nil {
log.Fatal(err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// create a gNMI client
err = tg.CreateGNMIClient(ctx)
if err != nil {
log.Fatal(err)
}
defer tg.Close()
// send a gNMI capabilities request to the created target
capResp, err := tg.Capabilities(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println(prototext.Format(capResp))
}