Please refer to Configd Client Library for the general concepts behind the API. This document will cover only Go specifics. The Go client library is fairly low level, like the C library. There are additional helper libraries that make the Go library easier to use. The "github.com/danos/utils/pathutil" library can do path encoding for the Go library allowing slices of strings to be used for paths in the programs using this API. The "github.com/danos/encoding/rfc7951/data" library is useful for handling the feature defined data returned from this API.
Before we can use the configd API we need to establish a connection to the daemon, instantiating the CfgClient object will do this. The destructor for the client object will close the connection.
Once connected we can do a variety of actions on the system, one can configure the device, request the operational state of the device, or perform feature specific RPCs. When configuring the device via the Configd APIs one follows much the same procedure as with the CLI. One creates a configuration session, makes changes, commits those changes, then tears down the session. One may view the RUNNING datastore without a session being created. Sessions persist process exit and must be explicitly removed with SessionTeardown. The minimal configuration application looks like the following.
From here, one may perform actions similar to what one does on the CLI. Since the interface here is meant for programatic interaction, one may also introspect on the data-model and the current state of the candidate tree to determine available actions, this is similar to using "tab-completion" to inspect the CLI.
The following example uses the Go configd API to set all dataplane interfaces to listen for DHCP addresses if no other address is assigned to that interface. While this is a silly thing to do, it demonstrates the basic mechanics of the this API.