This repository contains the Golang client to communicate with the Avisi Cloud Platform API.
To make use of this go-client include it in your go.mod file, e.g.:
go get github.com/avisi-cloud/go-client
To create a client that uses a personal access token (PAT) for authentication we first need to create a NewPersonalAccessTokenAuthenticator to which you pass in the PAT, e.g.:
authenticator := acloudapi.NewPersonalAccessTokenAuthenticator(token)
Then we create a ClientOpts
object in which you configure the URL of the Avisi Cloud Platform API you want to connect to, e.g.:
clientOpts := acloudapi.ClientOpts{
APIUrl: "https://example.com",
}
Next, create a NewCLient
, using the Authenticator
and ClientOpts
created in the previous steps:
c := acloudapi.NewClient(authenticator, clientOpts)
Full example:
personalAccessToken := os.Getenv("ACLOUD_PERSONAL_ACCESS_TOKEN")
authenticator := acloudapi.NewPersonalAccessTokenAuthenticator(personalAccessToken)
clientOpts := acloudapi.ClientOpts{
APIUrl: "https://example.com",
}
client := acloudapi.NewClient(authenticator, clientOpts)
createEnvironment := acloudapi.CreateEnvironment{
Name: "name",
Type: "staging",
Description: "a description of the environment",
}
org := "organisation-slug"
environment, err := client.CreateEnvironment(context.Background(), createEnvironment, org)
if err != nil {
return err
}
// environment has been created