cristaloleg / govultr

Vultr Go API client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GoVultr

Build Status GoDoc codecov Go Report Card

The official Vultr Go client - GoVultr allows you to interact with the Vultr V1 API.

Installation

go get -u github.com/vultr/govultr

Usage

Vultr uses a PAT (Personal Access token) to interact/authenticate with the APIs. An API Key can be generated and acquired from the API menu in settings.

To instantiate a govultr client you invoke NewClient().

This takes in two parameters:

  • *http.Client
  • API Key

You can define your own http.Client however if you pass in nil then you will be defaulted to use http.DefaultClient. For the API key, we recommend you store this as a environment variable and not hard code it.

There are also three optional parameters you may change regarding the client:

  • BaseUrl: allows you to override the base URL that Vultr defaults to
  • UserAgent: allows you to override the UserAgent that Vultr defaults to
  • RateLimit: Vultr currently rate limits how fast you can make calls back to back. This lets you configure if you want a delay in between calls

Example Client Setup

package main

import (
	"github.com/vultr/govultr"
	"os"
)

func main() {
	apiKey := os.Getenv("VultrAPIKey")

	vultrClient := govultr.NewClient(nil, apiKey)

	// Optional changes
	_ = vultrClient.SetBaseURL("https://api.vultr.com")
	vultrClient.SetUserAgent("mycool-app")
	vultrClient.SetRateLimit(500)
}

Example Usage

Create a VPS

vpsOptions := &govultr.ServerOptions{
	Label:                "awesome-go-app",
	Hostname:             "awesome-go.com",
	EnablePrivateNetwork: true,
	AutoBackups:          true,
	EnableIPV6:           true,
}

// RegionId, VpsPlanID, OsID can be grabbed from their respective API calls
res, err := vultrClient.Server.Create(context.Background(), 1, 201, 1, vpsOptions)

if err != nil {
	fmt.Println(err)
}

Versioning

This project follows SemVer for versioning. For the versions available, see the tags on this repository.

Documentation

For detailed information about our V1 API head over to our API documentation.

If you want more details about this client's functionality then check out our GoDoc documentation.

Contributing

Feel free to send pull requests our way! Please see the contributing guidelines.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

Vultr Go API client

License:MIT License


Languages

Language:Go 100.0%