Skip to content

netascode/go-restconf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Tests

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.

About

A Go client library for RESTCONF devices.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages