modulepackage
0.1.10
Repository: https://github.com/netascode/go-restconf.git
Documentation: pkg.go.dev
# README
go-restconf
go-restconf
is a Go client library for RESTCONF devices. It is based on Nathan's excellent goaci module and features a simple, extensible API and advanced JSON manipulation.
Getting Started
Installing
To start using go-restconf
, install Go and go get
:
$ go get -u github.com/netascode/go-restconf
Basic Usage
package main
import "github.com/netascode/go-resconf"
func main() {
client, _ := restconf.NewClient("https://1.1.1.1", "user", "pwd", true)
res, _ := client.GetData("Cisco-IOS-XE-native:native")
println(res.Res.Get("Cisco-IOS-XE-native:native.hostname").String())
}
This will print for example:
ROUTER-1
Result manipulation
restconf.Result
uses GJSON to simplify handling JSON results. See the GJSON documentation for more detail.
res, _ := client.GetData("Cisco-IOS-XE-native:native/interface/GigabitEthernet")
println(res.Res.Get("Cisco-IOS-XE-native:GigabitEthernet.0.name").String()) // name of first interface
for _, int := range res.Res.Get("Cisco-IOS-XE-native:GigabitEthernet").Array() {
println(int.Get("@pretty").Raw) // pretty print interface attributes
}
Helpers for common patterns
res, _ := client.GetData("Cisco-IOS-XE-native:native/hostname")
res, _ := client.DeleteData("Cisco-IOS-XE-native:native/banner/login/banner")
Query parameters
Pass the restconf.Query
object to the Get
request to add query parameters:
queryConfig := restconf.Query("content", "config")
res, _ := client.GetData("Cisco-IOS-XE-native:native", queryConfig)
Pass as many parameters as needed:
res, _ := client.GetData("Cisco-IOS-XE-native:native",
restconf.Query("content", "config"),
restconf.Query("depth", "1"),
)
POST data creation
restconf.Body
is a wrapper for SJSON. SJSON supports a path syntax simplifying JSON creation.
exampleUser := restconf.Body{}.Set("Cisco-IOS-XE-native:username.name", "test-user").Str
client.PostData("Cisco-IOS-XE-native:native", exampleUser)
These can be chained:
user1 := restconf.Body{}.
Set("Cisco-IOS-XE-native:username.name", "test-user").
Set("Cisco-IOS-XE-native:username.description", "My Test User")
...or nested:
attrs := restconf.Body{}.
Set("name", "test-user").
Set("description", "My Test User").
Str
user1 := restconf.Body{}.SetRaw("Cisco-IOS-XE-native:username", attrs).Str
Documentation
See the documentation for more details.
# Functions
BackoffDelayFactor modifies the backoff delay factor from the default of 3.
BackoffMaxDelay modifies the maximum delay between two retries from the default of 60.
BackoffMinDelay modifies the minimum delay between two retries from the default of 4.
MaxRetries modifies the maximum number of retries from the default of 2.
NewClient creates a new RESTCONF HTTP client.
Create new YangPathEdit for YangPatchData().
Query sets an HTTP query parameter.
RequestTimeout modifies the HTTP request timeout from the default of 60 seconds.
SkipDiscovery provides the otherwise dynamically discovered capabilities.
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
No description provided by the author
# Structs
Body wraps SJSON for building JSON body strings.
No description provided by the author
No description provided by the author
Client is an HTTP RESTCONF client.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Req wraps http.Request for API requests.
Res is an API response returned by client requests.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author