This is an SDK for interacting with ANS APIs from Go applications.
You should refer to the Getting Started section of the API documentation before proceeding below
First we'll instantiate a Client struct with an API key:
c := client.NewClient(connection.NewAPIKeyCredentialsAPIConnection("myapikey"))
And away we go:
service := c.SafeDNSService()
zone, err := service.GetZone("ans.co.uk")
fmt.Printf("Zone: %s", zone.Name)
Resources/models are separated into separate service packages, found within pkg/service
.
The SDK has default implementation for managing config, which is utilised by several utilities such as the CLI and Terraform providers. This config can be defined both within config files and environment variables.
There is a default connection factory included (pkg/connection/factory.go
) which utilises the config package, which can be used in your applications as below:
conn, err := connection.NewDefaultConnectionFactory().NewConnection()
if err != nil {
panic(err)
}
service := client.NewClient(conn).SafeDNSService()
The configuration file is read from
$HOME/.ans{.extension}
by default (extension being one of the viper
supported formats such as yml
, yaml
, json
, toml
etc.)
api_key
: (String) Required API key for authenticating with APIapi_timeout_seconds
: (int) HTTP timeout for API requests. Default:90
api_uri
: (string) API URI. Default:api.ukfast.io
api_insecure
: (bool) Specifies to ignore API certificate validation checks
Contexts can be defined in the config file to allow for different sets of configuration to be defined:
contexts:
testcontext1:
api_key: mykey1
testcontext2:
api_key: mykey2
current_context: testcontext1
These variables match the naming of directives in the configuration file defined above, however are uppercased and prefixed with ANS_
, such as ANS_API_KEY
Values defined in the configuration file take precedence over environment variables