All Projects → vultr → Govultr

vultr / Govultr

Licence: mit
Vultr Go API client

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Labels

Projects that are alternatives of or similar to Govultr

Apisix Ingress Controller
ingress controller for K8s
Stars: ✭ 139 (-3.47%)
Mutual labels:  api
Pycep Correios
📦 API para busca de CEP integrado ao serviços dos Correios, ViaCEP e ApiCEP (WideNet)
Stars: ✭ 141 (-2.08%)
Mutual labels:  api
Coinbasepro Csharp
The unofficial .NET/C# client library for the Coinbase Pro/GDAX API
Stars: ✭ 143 (-0.69%)
Mutual labels:  api
Awesome Documentation Tools
🔥 📚 All the tools, processes and resources you need to create an awesome API & Project documentation
Stars: ✭ 138 (-4.17%)
Mutual labels:  api
Js Libs
A collection of JavaScript libraries for Ethereum dapp development.
Stars: ✭ 141 (-2.08%)
Mutual labels:  api
Apifairy
A minimalistic API framework built on top of Flask, Marshmallow and friends.
Stars: ✭ 141 (-2.08%)
Mutual labels:  api
Cityengine Sdk
CityEngine is a 3D city modeling software for urban design, visual effects, and VR/AR production. With its C++ SDK you can create plugins and standalone apps capable to execute CityEngine CGA procedural modeling rules.
Stars: ✭ 137 (-4.86%)
Mutual labels:  api
Apis
Making data readily available to anyone interested
Stars: ✭ 143 (-0.69%)
Mutual labels:  api
Api Query Params
Convert URL query parameters to MongoDB queries
Stars: ✭ 141 (-2.08%)
Mutual labels:  api
Forecastr
A simple, asynchronous Objective-C wrapper for the Forecast.io API
Stars: ✭ 143 (-0.69%)
Mutual labels:  api
Archiveis
A simple Python wrapper for the archive.is capturing service
Stars: ✭ 140 (-2.78%)
Mutual labels:  api
Pytodoist
Use Todoist with Python ✅
Stars: ✭ 140 (-2.78%)
Mutual labels:  api
Smoke
💨 Simple yet powerful file-based mock server with recording abilities
Stars: ✭ 142 (-1.39%)
Mutual labels:  api
Migrationminer
A tool to detect migration code between two Java third-party libraries
Stars: ✭ 140 (-2.78%)
Mutual labels:  api
Thehive4py
Python API Client for TheHive
Stars: ✭ 143 (-0.69%)
Mutual labels:  api
Librouteros
Python implementation of MikroTik RouterOS API
Stars: ✭ 139 (-3.47%)
Mutual labels:  api
Coolapk Kotlin
酷安开源版.....
Stars: ✭ 141 (-2.08%)
Mutual labels:  api
Electron Extensions
Implementation of Chrome extension APIs for Electron
Stars: ✭ 143 (-0.69%)
Mutual labels:  api
Jsonrpc
The jsonrpc package helps implement of JSON-RPC 2.0
Stars: ✭ 143 (-0.69%)
Mutual labels:  api
Free Apis
free APIs. 工作和学习过程中收集的实用的免费 API 集合。
Stars: ✭ 142 (-1.39%)
Mutual labels:  api

GoVultr

Build Status PkgGoDev codecov 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].