Skip to content

ureuzy/acos-client-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

acos-client-go

License: MIT GitHub Action Test Go Report Card codecov Go Reference

A simple go client for a10 networks' aXAPI

ACOS 4.1.4-P1 aXAPIv3 Reference Document

Documentation

godoc

Supported Version

ACOS aXAPI Status
4.1.4 3

Install

go get -u github.com/ureuzy/acos-client-go

Usage

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)

example code

Optional Parameter

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)

Authenticate

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()

Handle aXAPI error response

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

Contribution

I welcome contributions. If you want to fix a problem, make an enhancement, etc., feel free to send a pull request.

About

Simple go client for a10 networks' ACOS aXAPI

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published