Documentation
¶
Overview ¶
Package restconf is a RESTCONF (RFC 8040) client library for Go.
Index ¶
- Constants
- func BackoffDelayFactor(x float64) func(*Client)
- func BackoffMaxDelay(x int) func(*Client)
- func BackoffMinDelay(x int) func(*Client)
- func MaxRetries(x int) func(*Client)
- func Query(k, v string) func(req *Req)
- func RequestTimeout(x time.Duration) func(*Client)
- type Body
- type Client
- func (client *Client) Backoff(attempts int) bool
- func (client *Client) DeleteData(path string, mods ...func(*Req)) (Res, int, error)
- func (client *Client) Do(req Req) (Res, int, error)
- func (client *Client) GetData(path string, mods ...func(*Req)) (Res, int, error)
- func (client Client) NewReq(method, uri string, body io.Reader, mods ...func(*Req)) Req
- func (client *Client) PatchData(path, data string, mods ...func(*Req)) (Res, int, error)
- func (client *Client) PostData(path, data string, mods ...func(*Req)) (Res, int, error)
- func (client *Client) PutData(path, data string, mods ...func(*Req)) (Res, int, error)
- type Req
- type Res
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func BackoffDelayFactor ¶
BackoffDelayFactor modifies the backoff delay factor from the default of 3.
func BackoffMaxDelay ¶
BackoffMaxDelay modifies the maximum delay between two retries from the default of 60.
func BackoffMinDelay ¶
BackoffMinDelay modifies the minimum delay between two retries from the default of 4.
func MaxRetries ¶
MaxRetries modifies the maximum number of retries from the default of 2.
func Query ¶
Query sets an HTTP query parameter.
client.GetData("Cisco-IOS-XE-native:native", restconf.Query("content", "config"))
Or set multiple parameters:
client.GetData("Cisco-IOS-XE-native:native",
restconf.Query("content", "config"),
restconf.Query("depth", "1"))
func RequestTimeout ¶
RequestTimeout modifies the HTTP request timeout from the default of 60 seconds.
Types ¶
type Body ¶
type Body struct {
Str string
}
Body wraps SJSON for building JSON body strings. Usage example:
Body{}.Set(Cisco-IOS-XE-native:native.hostname", "ROUTER-1").Str
type Client ¶
type Client struct {
// HttpClient is the *http.Client used for API requests.
HttpClient *http.Client
// Url is the device url.
Url string
// Usr is the device username.
Usr string
// Pwd is the device password.
Pwd string
// Insecure determines if insecure https connections are allowed.
Insecure bool
// Maximum number of retries
MaxRetries int
// Minimum delay between two retries
BackoffMinDelay int
// Maximum delay between two retries
BackoffMaxDelay int
// Backoff delay factor
BackoffDelayFactor float64
// Discovered RESTCONF API endpoint
RestconfEndpoint string
}
Client is an HTTP RESTCONF client. Use restconf.NewClient to initiate a client. This will ensure proper cookie handling and processing of modifiers.
func NewClient ¶
NewClient creates a new RESTCONF HTTP client. Pass modifiers in to modify the behavior of the client, e.g.
client, _ := NewClient("https://10.0.0.1", "user", "password", true, RequestTimeout(120))
func (*Client) DeleteData ¶
DeleteData makes a DELETE request and returns a GJSON result.
func (*Client) Do ¶
Do makes a request. Requests for Do are built ouside of the client, e.g.
req := client.NewReq("GET", "Cisco-IOS-XE-native:native/hostname", nil)
res, _ := client.Do(req)
func (*Client) PatchData ¶
PatchData makes a PATCH request and returns a GJSON result. Hint: Use the Body struct to easily create PATCH body data.
type Res ¶
Res is an API response returned by client requests. This is a GJSON result, which offers advanced and safe parsing capabilities. https://github.com/tidwall/gjson