Skip to content

avisi-cloud/go-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Avisi Cloud API go-client

Description

This repository contains the Golang client to communicate with the Avisi Cloud Platform API.

Website | Documentation

Installation

To make use of this go-client include it in your go.mod file, e.g.:

go get github.com/avisi-cloud/go-client

Getting Started

Usage

Setting up a 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)

Example

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

License

Apache 2.0 License 2.0