Documentation
¶
Overview ¶
Package goaci is a a Cisco ACI client library for Go.
Index ¶
- func NoRefresh(req *Req)
- func Query(k, v string) func(req *Req)
- func RequestTimeout(x time.Duration) func(*Client)
- type Body
- type Client
- func (client *Client) Do(req Req) (Res, error)
- func (client *Client) Get(path string, mods ...func(*Req)) (Res, error)
- func (client *Client) GetClass(class string, mods ...func(*Req)) (Res, error)
- func (client *Client) GetDn(dn string, mods ...func(*Req)) (Res, error)
- func (client *Client) Login() error
- func (client Client) NewReq(method, uri string, body io.Reader, mods ...func(*Req)) Req
- func (client *Client) Post(path, data string, mods ...func(*Req)) (Res, error)
- func (client *Client) Refresh() error
- type Req
- type Res
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NoRefresh ¶
func NoRefresh(req *Req)
NoRefresh prevents token refresh check. Primarily used by the Login and Refresh methods where this would be redundant.
func Query ¶
Query sets an HTTP query parameter.
client.GetClass("fvBD", goaci.Query("query-target-filter", `eq(fvBD.name,"bd-name")`))
Or set multiple parameters:
client.GetClass("fvBD",
goaci.Query("rsp-subtree-include", "faults"),
goaci.Query("query-target-filter", `eq(fvBD.name,"bd-name")`))
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("fvTenant.attributes.name", "mytenant").Str
type Client ¶ added in v0.2.0
type Client struct {
// HttpClient is the *http.Client used for API requests.
HttpClient *http.Client
// Url is the APIC IP or hostname, e.g. 10.0.0.1:80 (port is optional).
Url string
// Usr is the APIC username.
Usr string
// Pwd is the APIC password.
Pwd string
// LastRefresh is the timestamp of the last token refresh interval.
LastRefresh time.Time
// Token is the current authentication token
Token string
}
Client is an HTTP ACI API client. Use goaci.NewClient to initiate a client. This will ensure proper cookie handling and processing of modifiers.
func NewClient ¶ added in v0.2.0
NewClient creates a new ACI HTTP client. Pass modifiers in to modify the behavior of the client, e.g.
client, _ := NewClient("apic", "user", "password", RequestTimeout(120))
func (*Client) Do ¶ added in v0.4.0
Do makes a request. Requests for Do are built ouside of the client, e.g.
req := client.NewReq("GET", "/api/class/fvBD", nil)
res := client.Do(req)
func (*Client) Get ¶ added in v0.2.0
Get makes a GET request and returns a GJSON result. Results will be the raw data structure as returned by the APIC, wrapped in imdata, e.g.
{
"imdata": [
{
"fvTenant": {
"attributes": {
"dn": "uni/tn-mytenant",
"name": "mytenant",
}
}
}
],
"totalCount": "1"
}
func (*Client) GetClass ¶ added in v0.2.0
GetClass makes a GET request by class and unwraps the results. Result is removed from imdata, but still wrapped in Class.attributes, e.g.
[
{
"fvTenant": {
"attributes": {
"dn": "uni/tn-mytenant",
"name": "mytenant",
}
}
}
]
func (*Client) GetDn ¶ added in v0.2.0
GetDn makes a GET request by DN. Result is removed from imdata and first result is removed from the list, e.g.
{
"fvTenant": {
"attributes": {
"dn": "uni/tn-mytenant",
"name": "mytenant",
}
}
}
func (*Client) Post ¶ added in v0.2.0
Post makes a POST request and returns a GJSON result. Hint: Use the Body struct to easily create POST body data.
func (*Client) Refresh ¶ added in v0.2.0
Refresh refreshes the authentication token. Note that this will be handled automatically be default. Refresh will be checked every request and the token will be refreshed after 8 minutes. Pass goaci.NoRefresh to prevent automatic refresh handling and handle it directly instead.
type Req ¶
type Req struct {
// HttpReq is the *http.Request obejct.
HttpReq *http.Request
// Refresh indicates whether token refresh should be checked for this request.
// Pass NoRefresh to disable Refresh check.
Refresh bool
}
Req wraps http.Request for API requests.
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