Categorygithub.com/vultr/govultr/v2
modulepackage
2.17.2
Repository: https://github.com/vultr/govultr.git
Documentation: pkg.go.dev

# README

GoVultr

Automatic Releaser PkgGoDev Unit/Coverage Tests Go Report Card

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

GoVultr V1 that interacts with Vultr V1 API is now on the v1 branch

Installation

go get -u github.com/vultr/govultr/v2

Usage

Vultr uses a PAT (Personal Access token) to interact/authenticate with the APIs. Generate an API Key from the API menu in the Vultr Customer Portal.

To instantiate a GoVultr client, invoke NewClient(). You must pass your PAT to an oauth2 library to create the *http.Client, which configures the Authorization header with your PAT as the bearer api-key.

The client has three optional parameters:

  • BaseUrl: Change the Vultr default base URL
  • UserAgent: Change the Vultr default UserAgent
  • RateLimit: Set a delay between calls. Vultr limits the rate of back-to-back calls. Use this parameter to avoid rate-limit errors.

Example Client Setup

package main

import (
  "context"
  "os"

  "github.com/vultr/govultr/v2"
  "golang.org/x/oauth2"
)

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

  config := &oauth2.Config{}
  ctx := context.Background()
  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)
}

Example Usage

Create a VPS

instanceOptions := &govultr.InstanceCreateReq{
  Label:                "awesome-go-app",
  Hostname:             "awesome-go.com",
  Backups:              "enabled",
  EnableIPv6:           BoolToBoolPtr(false),
  OsID:                 362,
  Plan:                 "vc2-1c-2gb",   
  Region:               "ewr",
}

res, err := vultrClient.Instance.Create(context.Background(), instanceOptions)

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

Pagination

GoVultr v2 introduces pagination for all list calls. Each list call returns a meta struct containing the total amount of items in the list and next/previous links to navigate the paging.

// Meta represents the available pagination information
type Meta struct {
  Total int `json:"total"`
  Links *Links
}

// Links represent the next/previous cursor in your pagination calls
type Links struct {
  Next string `json:"next"`
  Prev string `json:"prev"`
}

Pass a per_page value to the list_options struct to adjust the number of items returned per call. The default is 100 items per page and max is 500 items per page.

This example demonstrates how to retrieve all of your instances, with one instance per page.

listOptions := &govultr.ListOptions{PerPage: 1}
for {
    i, meta, err := client.Instance.List(ctx, listOptions)
    if err != nil {
        return nil, err
    }
    for _, v := range i {
        fmt.Println(v)
    }

    if meta.Links.Next == "" {
        break
    } else {
        listOptions.Cursor = meta.Links.Next
        continue
    }
}    

Versioning

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

Documentation

See our documentation for detailed information about API v2.

See our GoDoc documentation for more details about this client's functionality.

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.

# Functions

BoolToBoolPtr helper function that returns a pointer from your bool value.
IntToIntPtr helper function that returns a pointer from your string value.
NewClient returns a Vultr API Client.
StringToStringPtr helper function that returns a pointer from your string value.

# Structs

Account represents a Vultr account.
AccountServiceHandler handles interaction with the account methods for the Vultr API.
APIKey contains a users API Key for interacting with the API.
Application represents all available apps that can be used to deployed with vultr Instances.
ApplicationServiceHandler handles interaction with the application methods for the Vultr API.
Backup represents a Vultr backup.
BackupSchedule information for a given instance.
BackupScheduleReq struct used to create a backup schedule for an instance.
BackupServiceHandler handles interaction with the backup methods for the Vultr API.
Bandwidth used on a given instance.
BareMetalCreate represents the optional parameters that can be set when creating a Bare Metal server.
BareMetalPlan represents bare metal plans.
BareMetalServer represents a Bare Metal server on Vultr.
BareMetalServerBandwidth represents bandwidth information for a Bare Metal server.
BareMetalServerServiceHandler handles interaction with the Bare Metal methods for the Vultr API.
BareMetalUpdate represents the optional parameters that can be set when updating a Bare Metal server.
BillingServiceHandler handles interaction with the billing methods for the Vultr API.
BlockStorage represents Vultr Block-Storage.
BlockStorageAttach struct used to define if a attach should be restart the instance.
BlockStorageCreate struct is used for creating Block Storage.
BlockStorageDetach struct used to define if a detach should be restart the instance.
BlockStorageServiceHandler handles interaction with the block-storage methods for the Vultr API.
BlockStorageUpdate struct is used to update Block Storage.
BMBareMetalBase ...
Client manages interaction with the Vultr V1 API.
Cluster represents a full VKE cluster.
ClusterReq struct used to create a cluster.
ClusterReqUpdate struct used to update update a cluster.
ClusterUpgradeReq struct for vke upgradse.
Domain represents a Domain entry on Vultr.
DomainRecord represents a DNS record on Vultr.
DomainRecordReq struct to use for create/update domain record calls.
DomainRecordsServiceHandler handles interaction with the DNS Records methods for the Vultr API.
DomainReq is the struct to create a domain If IP is omitted then an empty DNS entry will be created.
DomainServiceHandler handles interaction with the DNS methods for the Vultr API.
FirewallGroup represents a Vultr firewall group.
FirewallGroupReq struct is used to create and update a Firewall Group.
FireWallGroupServiceHandler handles interaction with the firewall group methods for the Vultr API.
FirewallRule represents a Vultr firewall rule.
FirewallRuleReq struct used to create a FirewallRule.
FireWallRuleServiceHandler handles interaction with the firewall rule methods for the Vultr API.
ForwardingRule represent a single forwarding rule.
ForwardingRules represent a list of forwarding rules.
GenericInfo represents generic configuration of your load balancer.
HealthCheck represents your health check configuration for your load balancer.
History represents a billing history item on an account.
Instance represents a VPS.
InstanceCreateReq struct used to create an instance.
InstanceList represents instances that are attached to your load balancer.
InstanceServiceHandler handles interaction with the server methods for the Vultr API.
InstanceUpdateReq struct used to update an instance.
Invoice represents an invoice on an account.
InvoiceItem represents an item on an accounts invoice.
IPv4 struct.
IPv6 struct.
Iso information for a given instance.
ISO represents ISOs currently available on this account.
ISOReq is used for creating ISOs.
ISOServiceHandler handles interaction with the ISO methods for the Vultr API.
KubeConfig will contain the kubeconfig b64 encoded.
KubernetesHandler handles interaction with the kubernetes methods for the Vultr API.
LBFirewallRule represent a single firewall rule.
Links represent the next/previous cursor in your pagination calls.
ListOptions are the available query params.
LoadBalancer represent the structure of a load balancer.
LoadBalancerHandler handles interaction with the server methods for the Vultr API.
LoadBalancerReq gives options for creating or updating a load balancer.
Meta represents the available pagination information.
Neighbors that might exist on the same host.
Network represents a Vultr private network Deprecated: Network should no longer be used.
NetworkReq represents parameters to create or update Network resource Deprecated: NetworkReq should no longer be used.
NetworkServiceHandler handles interaction with the network methods for the Vultr API Deprecated: NetworkServiceHandler should no longer be used.
Node represents a node that will live within a nodepool.
NodePool represents a pool of nodes that are grouped by their label and plan type.
NodePoolReq struct used to create a node pool.
NodePoolReqUpdate struct used to update a node pool.
ObjectStorage represents a Vultr Object Storage subscription.
ObjectStorageCluster represents a Vultr Object Storage cluster.
ObjectStorageServiceHandler handles interaction with the firewall rule methods for the Vultr API.
OS represents a Vultr operating system.
OSServiceHandler handles interaction with the operating system methods for the Vultr API.
Plan represents vc2, vdc, or vhf.
PlanAvailability contains all available plans.
PlanServiceHandler handles interaction with the Plans methods for the Vultr API.
PrivateNetwork information for a given instance.
PublicISO represents public ISOs offered in the Vultr ISO library.
Region represents a Vultr region.
RegionServiceHandler handles interaction with the region methods for the Vultr API.
ReinstallReq struct used to allow changes during a reinstall.
ReservedIP represents an reserved IP on Vultr.
ReservedIPConvertReq is the struct used for create and update calls.
ReservedIPReq represents the parameters for creating a new Reserved IP on Vultr.
ReservedIPServiceHandler handles interaction with the reserved IP methods for the Vultr API.
ReservedIPUpdateReq represents the parameters for updating a Reserved IP on Vultr.
RestoreReq struct used to supply whether a restore should be from a backup or snapshot.
ReverseIP information for a given instance.
S3Keys define your api access to your cluster.
Snapshot represents a Vultr snapshot.
SnapshotReq struct is used to create snapshots.
SnapshotServiceHandler handles interaction with the snapshot methods for the Vultr API.
SnapshotURLReq struct is used to create snapshots from a URL.
Soa information for the Domain.
SSHKey represents an SSH Key on Vultr.
SSHKeyReq is the ssh key struct for create and update calls.
SSHKeyServiceHandler handles interaction with the SSH Key methods for the Vultr API.
SSL represents valid SSL config.
StartupScript represents an startup script on Vultr.
StartupScriptReq is the user struct for create and update calls.
StartupScriptServiceHandler handles interaction with the startup script methods for the Vultr API.
StickySessions represents cookie for your load balancer.
Upgrades that are available for a given Instance.
User represents an user on Vultr.
UserData information for a given struct.
UserReq is the user struct for create and update calls.
UserServiceHandler handles interaction with the user methods for the Vultr API.
Versions that are supported for VKE.
VNCUrl contains the URL for a given Bare Metals VNC.
VPC represents a Vultr VPC.
VPCInfo information for a given instance.
VPCReq represents parameters to create or update a VPC resource.
VPCServiceHandler handles interaction with the VPC methods for the Vultr API.

# Interfaces

AccountService is the interface to interact with Accounts endpoint on the Vultr API Link : https://www.vultr.com/api/#tag/account.
ApplicationService is the interface to interact with the Application endpoint on the Vultr API.
BackupService is the interface to interact with the backup endpoint on the Vultr API Link : https://www.vultr.com/api/#tag/backup.
BareMetalServerService is the interface to interact with the Bare Metal endpoints on the Vultr API Link : https://www.vultr.com/api/#tag/baremetal.
BillingService is the interface to interact with the billing endpoint on the Vultr API Link : https://www.vultr.com/api/#tag/billing.
BlockStorageService is the interface to interact with Block-Storage endpoint on the Vultr API Link : https://www.vultr.com/api/#tag/block.
DomainRecordService is the interface to interact with the DNS Records endpoints on the Vultr API Link: https://www.vultr.com/api/#tag/dns.
DomainService is the interface to interact with the DNS endpoints on the Vultr API https://www.vultr.com/api/#tag/dns.
FirewallGroupService is the interface to interact with the firewall group endpoints on the Vultr API Link : https://www.vultr.com/api/#tag/firewall.
FireWallRuleService is the interface to interact with the firewall rule endpoints on the Vultr API Link : https://www.vultr.com/api/#tag/firewall.
InstanceService is the interface to interact with the instance endpoints on the Vultr API Link: https://www.vultr.com/api/#tag/instances.
ISOService is the interface to interact with the ISO endpoints on the Vultr API Link : https://www.vultr.com/api/#tag/iso.
KubernetesService is the interface to interact with kubernetes endpoint on the Vultr API Link : https://www.vultr.com/api/#tag/kubernetes.
LoadBalancerService is the interface to interact with the server endpoints on the Vultr API Link : https://www.vultr.com/api/#tag/load-balancer.
NetworkService is the interface to interact with the network endpoints on the Vultr API Link : https://www.vultr.com/api/#tag/private-Networks Deprecated: NetworkService should no longer be used.
ObjectStorageService is the interface to interact with the object storage endpoints on the Vultr API.
OSService is the interface to interact with the operating system endpoint on the Vultr API Link : https://www.vultr.com/api/#tag/os.
PlanService is the interface to interact with the Plans endpoints on the Vultr API Link : https://www.vultr.com/api/#tag/plans.
RegionService is the interface to interact with Region endpoints on the Vultr API Link : https://www.vultr.com/api/#tag/region.
ReservedIPService is the interface to interact with the reserved IP endpoints on the Vultr API Link : https://www.vultr.com/api/#tag/reserved-ip.
SnapshotService is the interface to interact with Snapshot endpoints on the Vultr API Link : https://www.vultr.com/api/#tag/snapshot.
SSHKeyService is the interface to interact with the SSH Key endpoints on the Vultr API Link : https://www.vultr.com/api/#tag/ssh.
StartupScriptService is the interface to interact with the startup script endpoints on the Vultr API Link : https://www.vultr.com/api/#tag/startup.
UserService is the interface to interact with the user management endpoints on the Vultr API Link : https://www.vultr.com/api/#tag/users.
VPCService is the interface to interact with the VPC endpoints on the Vultr API Link : https://www.vultr.com/api/#tag/vpcs.

# Type aliases

RequestBody is used to create JSON bodies for one off calls.
RequestCompletionCallback defines the type of the request callback function.