A simple go client for a10 networks' aXAPI
ACOS 4.1.4-P1 aXAPIv3 Reference Document
ACOS | aXAPI | Status |
---|---|---|
4.1.4 | 3 | ✅ |
go get -u github.com/ureuzy/acos-client-go
Import
import "github.com/ureuzy/acos-client-go"
New client
config := client.Config{Host: "<HOST>", User: "<USER>", Pass: "<PASS>", Debug: false}
c, _ := client.NewAuthenticated(config)
// Get virtual server
vs, _ := c.Slb.VirtualServer.Get("ureuzy-sample-virtualserver")
fmt.Println(vs.Name, vs.IPAddress)
When creating a client, you can accept optional arguments and customize the http client
customHTTPClient := func(client *http.Client) {
client = &http.Client{}
}
client.NewAuthenticated(config, customHTTPClient)
There are also several options available that are likely to be used more frequently and can be used.
TLS insecure skip verify
opt := func(c *http.Client) {
c.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
}
c, err := client.NewAuthenticated(config, opt)
Authenticated and unauthenticated clients can be created.
c, _ := client.NewAuthenticated(config) // Authenticated
c := client.NewInstance(config) // Unauthenticated
Unauthenticated clients or tokens that have expired can be re-authenticated
c.Authenticate()
acos-client-go treats HTTP responses of 400 or more from aXAPI as errors. The response is wrapped as an error and can be unwrapped
import "github.com/ureuzy/acos-client-go/pkg/axapi/errors"
err = c.Slb.VirtualServer.Delete("not-exist-virtualserver")
if errRes, ok := err.(*errors.ResponseBody); err != nil && ok {
fmt.Printf("status: %s, msg: %s\n", errRes.Status, errRes.Msg)
}
status: fail, msg: Object slb virtual-server {not-exist-virtualserver} does not exist
I welcome contributions. If you want to fix a problem, make an enhancement, etc., feel free to send a pull request.