The official Vultr Go client - GoVultr allows you to interact with the Vultr V2 API.
go get -u github.com/vultr/govultr
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()
.
You will also have to pass in your PAT
to a oauth2
library to create an *http.Client
which will configure Authorization
header with your PAT as bearer api-key
.
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
package main
import (
"github.com/vultr/govultr"
"os"
)
func main() {
apiKey := os.Getenv("VultrAPIKey")
config := &oauth2.Config{}
ts := config.TokenSource(ctx, &oauth2.Token{AccessToken: apiKey})
vultrClient := govultr.NewClient(oauth2.NewClient(ctx,ts))
// Optional changes
_ = vultrClient.SetBaseURL("https://api.vultr.com")
vultrClient.SetUserAgent("mycool-app")
vultrClient.SetRateLimit(500)
}
Create a VPS
instanceOptions := &govultr.InstanceReq{
Label: "awesome-go-app",
Hostname: "awesome-go.com",
Backups: true,
EnableIPv6: true,
OsID: 362,
Plan: "vc2-1c-2gb",
Region: "ewr",
}
res, err := vultrClient.Instance.Create(context.Background(), instanceOptions)
if err != nil {
fmt.Println(err)
}
This project follows SemVer for versioning. For the versions available, see the tags on this repository.
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.
Feel free to send pull requests our way! Please see the contributing guidelines.
This project is licensed under the MIT License - see the LICENSE.md file for details.