GO SDK of the GreenHost API. forked from github.com/digitalocean/godo
Go to file
Kiara Grouwstra 63c3cb3677 rm 2022-08-14 19:39:54 +02:00
.github/workflows go 1.18 (#529) 2022-04-13 09:58:42 -05:00
metrics Add support for retrieving Droplet monitoring metrics. (#491) 2021-11-01 15:31:17 -04:00
util util: update droplet create example (#538) 2022-06-14 17:16:38 -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 docs: Update links to API documentation. (#467) 2021-07-26 11:34:46 -04:00
1-click_test.go kubernetes - add support for surge upgrades (#355) 2020-07-16 18:28:55 -04:00
CHANGELOG.md Prep v1.81.0 release. (#539) 2022-06-15 14:04:47 -04:00
CONTRIBUTING.md CONTRIBUTING.md: Suggest using github-changelog-generator. (#404) 2020-10-27 11:44:55 -04:00
LICENSE.txt
README.md registry: Add ListManfiests and ListRepositoriesV2 api endpoint support + Token pagination (#501) 2021-12-03 10:07:08 -05:00
account.go Add support for Reserved IP addresses (#532) 2022-06-15 13:09:11 -04:00
account_test.go Add support for Reserved IP addresses (#532) 2022-06-15 13:09:11 -04:00
action.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
action_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
apps.gen.go Ntate/detection models (#543) 2022-07-27 16:53:29 -05:00
apps.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
apps_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
balance.go Update links to API documentation (#540) 2022-06-29 12:22:32 -04:00
balance_test.go Return balance values from Balance.Get 2019-12-11 15:53:37 -06:00
billing_history.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
billing_history_test.go Add BillingHistory service and List endpoint 2020-02-28 13:09:24 -06:00
cdn.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
cdn_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
certificates.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
certificates_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
databases.go databases: Support advanced config endpoints. (#542) 2022-07-29 16:05:07 -04:00
databases_test.go databases: Support advanced config endpoints. (#542) 2022-07-29 16:05:07 -04:00
doc.go Fix typo on "DigitalOcean" (#486) 2021-10-07 09:53:40 -04:00
domains.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
domains_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
droplet_actions.go Fix typos and grammar issues in comments (#495) 2021-11-01 10:34:57 -04:00
droplet_actions_test.go Remove updrage droplet action (deprecated) 2018-05-10 14:00:22 -07:00
droplets.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
droplets_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
errors.go
errors_test.go
firewalls.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
firewalls_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
floating_ips.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
floating_ips_actions.go docs: Update links to API documentation. (#467) 2021-07-26 11:34:46 -04:00
floating_ips_actions_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
floating_ips_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
go.mod go 1.18 (#529) 2022-04-13 09:58:42 -05:00
go.sum go 1.18 (#529) 2022-04-13 09:58:42 -05:00
godo.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
godo_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
image_actions.go image id: int -> string 2022-08-01 20:44:49 +02:00
image_actions_test.go image id: int -> string 2022-08-01 20:44:49 +02:00
images.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
images_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
invoices.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
invoices_test.go invoices: add category to InvoiceItem (#357) 2020-07-21 12:11:09 -04:00
keys.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
keys_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
kubernetes.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
kubernetes_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
links.go registry: Add ListManfiests and ListRepositoriesV2 api endpoint support + Token pagination (#501) 2021-12-03 10:07:08 -05:00
links_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
load_balancers.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
load_balancers_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
meta.go Remove links and meta fields from stubbed Get{Volume,Snapshot} response 2019-12-11 00:43:58 +01:00
monitoring.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
monitoring_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
projects.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
projects_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
regions.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
regions_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
registry.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
registry_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
reserved_ips.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
reserved_ips_actions.go Add support for Reserved IP addresses (#532) 2022-06-15 13:09:11 -04:00
reserved_ips_actions_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
reserved_ips_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
sizes.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
sizes_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
snapshots.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
snapshots_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
storage.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
storage_actions.go Fix typos and grammar issues in comments (#495) 2021-11-01 10:34:57 -04:00
storage_actions_test.go Deserialize meta field for remaining APIs 2019-12-12 09:46:43 +01:00
storage_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
strings.go Fix golint issues #377 2020-10-07 11:15:22 +05:30
tags.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
tags_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
timestamp.go
timestamp_test.go
vpcs.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02:00
vpcs_test.go ditch pagination, unused on greenhost 2022-08-14 19:34:48 +02: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://docs.digitalocean.com/reference/api/api-reference/

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-20-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
}

Some endpoints offer token based pagination. For example, to fetch all Registry Repositories:

func ListRepositoriesV2(ctx context.Context, client *godo.Client, registryName string) ([]*godo.RepositoryV2, error) {
    // create a list to hold our registries
    list := []*godo.RepositoryV2{}

    // create options. initially, these will be blank
    opt := &godo.TokenListOptions{}
    for {
        repositories, resp, err := client.Registry.ListRepositoriesV2(ctx, registryName, opt)
        if err != nil {
            return nil, err
        }

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

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

        // grab the next page token
        nextPageToken, err := resp.Links.NextPageToken()
        if err != nil {
            return nil, err
        }

        // provide the next page token for the next request
        opt.Token = nextPageToken
    }

    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.