GO SDK of the GreenHost API. forked from github.com/digitalocean/godo
Go to file
Ben Tranter 7ca5525843
Merge pull request #380 from DonRenando/main
refactor: Cyclomatic complexity issue
2020-10-06 17:41:58 -04:00
.github/workflows convert master to main 2020-06-29 11:51:16 -07:00
util Remove support for Go 1.6 (#166) 2018-05-08 16:24:29 -04:00
.gitignore Add support for LoadBalancers 2017-02-14 15:36:18 -05:00
.whitesource convert master to main 2020-06-29 11:51:16 -07:00
1-click.go kubernetes - add support for surge upgrades (#355) 2020-07-16 18:28:55 -04:00
1-click_test.go kubernetes - add support for surge upgrades (#355) 2020-07-16 18:28:55 -04:00
CHANGELOG.md Prepare to release v1.46.0 2020-10-05 14:59:54 -04:00
CONTRIBUTING.md convert master to main 2020-06-29 11:51:16 -07:00
LICENSE.txt Update copyright notice to 2016 [ci skip] 2016-01-03 19:46:24 +05:30
README.md Make readme exemple compile (#349) 2020-07-14 16:11:53 -04:00
account.go Adding `VolumeLimit` to account. 2018-08-30 12:55:21 -04:00
account_test.go Adding `VolumeLimit` to account. 2018-08-30 12:55:21 -04:00
action.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
action_test.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
apps.gen.go Run gofmt to fix some issues in codebase 2020-10-06 21:01:41 +02:00
apps.go update apps types to latest (#369) 2020-09-23 12:26:56 -04:00
apps_test.go update apps types to latest (#369) 2020-09-23 12:26:56 -04:00
balance.go Return balance values from Balance.Get 2019-12-11 15:53:37 -06:00
balance_test.go Return balance values from Balance.Get 2019-12-11 15:53:37 -06:00
billing_history.go fixup! Add BillingHistory service and List endpoint 2020-03-02 10:45:56 -06:00
billing_history_test.go Add BillingHistory service and List endpoint 2020-02-28 13:09:24 -06:00
cdn.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
cdn_test.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
certificates.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
certificates_test.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
databases.go Add reset user auth routes to db service 2020-03-04 11:26:26 -08:00
databases_test.go Run gofmt to fix some issues in codebase 2020-10-06 21:01:41 +02:00
doc.go Remove databases info from top-level godoc string 2019-11-25 16:33:11 -05:00
domains.go domains: Allow for SRV records with port 0. (#360) 2020-08-06 17:17:54 -04:00
domains_test.go Add RecordsByType, RecordsByName and RecordsByTypeAndNameto DomainsService 2020-06-09 08:46:02 -04:00
droplet_actions.go Remove updrage droplet action (deprecated) 2018-05-10 14:00:22 -07:00
droplet_actions_test.go Remove updrage droplet action (deprecated) 2018-05-10 14:00:22 -07:00
droplets.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
droplets_test.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
errors.go Add checks for arguments 2015-09-25 14:44:20 -05:00
errors_test.go Add checks for arguments 2015-09-25 14:44:20 -05:00
firewalls.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
firewalls_test.go Run gofmt to fix some issues in codebase 2020-10-06 21:01:41 +02:00
floating_ips.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
floating_ips_actions.go Remove support for Go 1.6 (#166) 2018-05-08 16:24:29 -04:00
floating_ips_actions_test.go use http.MethodX instead of "GET"/"POST"/"DELETE" 2017-07-02 13:55:56 +02:00
floating_ips_test.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
go.mod Update vulnerable x/crypto dependency 2020-04-21 12:33:22 -04:00
go.sum Install 1-click applications on a Kubernetes cluster (#341) 2020-06-18 10:54:13 -04:00
godo.go Prepare to release v1.46.0 2020-10-05 14:59:54 -04:00
godo_test.go Fix bug in rate limit race test 2020-10-01 11:04:11 +02:00
image_actions.go Remove support for Go 1.6 (#166) 2018-05-08 16:24:29 -04:00
image_actions_test.go use http.MethodX instead of "GET"/"POST"/"DELETE" 2017-07-02 13:55:56 +02:00
images.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
images_test.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
invoices.go invoices: add category to InvoiceItem (#357) 2020-07-21 12:11:09 -04:00
invoices_test.go invoices: add category to InvoiceItem (#357) 2020-07-21 12:11:09 -04:00
keys.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
keys_test.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
kubernetes.go Kubernetes: add taints field to node pool create and update requests 2020-09-21 16:54:42 +02:00
kubernetes_test.go Run gofmt to fix some issues in codebase 2020-10-06 21:01:41 +02:00
links.go update isLast to check p.Next 2019-10-17 19:08:28 -07:00
links_test.go fix variable name capitalization 2019-10-30 16:52:15 -07:00
load_balancers.go load balancers: add new size slug field 2020-10-02 14:07:46 -07:00
load_balancers_test.go Run gofmt to fix some issues in codebase 2020-10-06 21:01:41 +02:00
meta.go Remove links and meta fields from stubbed Get{Volume,Snapshot} response 2019-12-11 00:43:58 +01:00
projects.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
projects_test.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
regions.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
regions_test.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
registry.go registry: URL encode repository names when building URLs (#336) 2020-05-29 13:21:04 -04:00
registry_test.go registry: URL encode repository names when building URLs (#336) 2020-05-29 13:21:04 -04:00
sizes.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
sizes_test.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
snapshots.go Deserialize meta for storage 2019-12-11 00:43:58 +01:00
snapshots_test.go add support for tagging snapshots 2019-04-19 14:36:46 -04:00
storage.go Merge branch 'master' into deserialize-meta 2019-12-11 07:38:46 -08:00
storage_actions.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
storage_actions_test.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
storage_test.go Remove links and meta fields from stubbed Get{Volume,Snapshot} response 2019-12-11 00:43:58 +01:00
strings.go add projects support 2018-10-16 17:29:54 +00:00
tags.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
tags_test.go refactor: Cyclomatic complexity issue 2020-10-06 22:45:05 +02:00
timestamp.go removed named return 2015-07-16 09:16:00 +05:30
timestamp_test.go make linters happy 2016-12-20 16:00:17 -08:00
vpcs.go Add VPC v3 attributes 2020-03-30 09:09:07 -04:00
vpcs_test.go Add VPC v3 attributes 2020-03-30 09:09:07 -04:00

README.md

Godo

Build Status GoDoc

Godo is a Go client library for accessing the DigitalOcean V2 API.

You can view the client API docs here: http://godoc.org/github.com/digitalocean/godo

You can view DigitalOcean API docs here: https://developers.digitalocean.com/documentation/v2/

Install

go get github.com/digitalocean/godo@vX.Y.Z

where X.Y.Z is the version you need.

or

go get github.com/digitalocean/godo

for non Go modules usage or latest version.

Usage

import "github.com/digitalocean/godo"

Create a new DigitalOcean client, then use the exposed services to access different parts of the DigitalOcean API.

Authentication

Currently, Personal Access Token (PAT) is the only method of authenticating with the API. You can manage your tokens at the DigitalOcean Control Panel Applications Page.

You can then use your token to create a new client:

package main

import (
    "github.com/digitalocean/godo"
)

func main() {
    client := godo.NewFromToken("my-digitalocean-api-token")
}

If you need to provide a context.Context to your new client, you should use godo.NewClient to manually construct a client instead.

Examples

To create a new Droplet:

dropletName := "super-cool-droplet"

createRequest := &godo.DropletCreateRequest{
    Name:   dropletName,
    Region: "nyc3",
    Size:   "s-1vcpu-1gb",
    Image: godo.DropletCreateImage{
        Slug: "ubuntu-14-04-x64",
    },
}

ctx := context.TODO()

newDroplet, _, err := client.Droplets.Create(ctx, createRequest)

if err != nil {
    fmt.Printf("Something bad happened: %s\n\n", err)
    return err
}

Pagination

If a list of items is paginated by the API, you must request pages individually. For example, to fetch all Droplets:

func DropletList(ctx context.Context, client *godo.Client) ([]godo.Droplet, error) {
    // create a list to hold our droplets
    list := []godo.Droplet{}

    // create options. initially, these will be blank
    opt := &godo.ListOptions{}
    for {
        droplets, resp, err := client.Droplets.List(ctx, opt)
        if err != nil {
            return nil, err
        }

        // append the current page's droplets to our list
        list = append(list, droplets...)

        // if we are at the last page, break out the for loop
        if resp.Links == nil || resp.Links.IsLastPage() {
            break
        }

        page, err := resp.Links.CurrentPage()
        if err != nil {
            return nil, err
        }

        // set the page we want for the next request
        opt.Page = page + 1
    }

    return list, nil
}

Versioning

Each version of the client is tagged and the version is updated accordingly.

To see the list of past versions, run git tag.

Documentation

For a comprehensive list of examples, check out the API documentation.

For details on all the functionality in this library, see the GoDoc documentation.

Contributing

We love pull requests! Please see the contribution guidelines.