• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/workflows/H05-Aug-2021-

util/H05-Aug-2021-

.gitignoreH A D05-Aug-20218

.whitesourceH A D05-Aug-2021139

1-click.goH A D05-Aug-20212.4 KiB

1-click_test.goH A D05-Aug-20211.4 KiB

CHANGELOG.mdH A D05-Aug-202112.2 KiB

CONTRIBUTING.mdH A D05-Aug-20212.3 KiB

README.mdH A D05-Aug-20213.6 KiB

account.goH A D05-Aug-20211.5 KiB

account_test.goH A D05-Aug-20211.6 KiB

action.goH A D05-Aug-20212.5 KiB

action_test.goH A D05-Aug-20213.4 KiB

apps.gen.goH A D05-Aug-202136.3 KiB

apps.goH A D05-Aug-202112.1 KiB

apps_test.goH A D05-Aug-202115.9 KiB

balance.goH A D05-Aug-20211.3 KiB

balance_test.goH A D05-Aug-2021884

billing_history.goH A D05-Aug-20211.9 KiB

billing_history_test.goH A D05-Aug-20211.7 KiB

cdn.goH A D05-Aug-20215.9 KiB

cdn_test.goH A D05-Aug-202111.6 KiB

certificates.goH A D05-Aug-20213.8 KiB

certificates_test.goH A D05-Aug-20216.8 KiB

databases.goH A D05-Aug-202131.6 KiB

databases_test.goH A D05-Aug-202136.3 KiB

doc.goH A D05-Aug-202170

domains.goH A D05-Aug-202111.4 KiB

domains_test.goH A D05-Aug-202113.9 KiB

droplet_actions.goH A D05-Aug-202111.7 KiB

droplet_actions_test.goH A D05-Aug-202125.2 KiB

droplets.goH A D05-Aug-202116.3 KiB

droplets_test.goH A D05-Aug-202117.7 KiB

errors.goH A D05-Aug-2021490

errors_test.goH A D05-Aug-2021255

firewalls.goH A D05-Aug-20219 KiB

firewalls_test.goH A D05-Aug-202118.9 KiB

floating_ips.goH A D05-Aug-20213.7 KiB

floating_ips_actions.goH A D05-Aug-20213.2 KiB

floating_ips_actions_test.goH A D05-Aug-20214.5 KiB

floating_ips_test.goH A D05-Aug-20214.5 KiB

go.modH A D05-Aug-2021507

go.sumH A D05-Aug-20213.9 KiB

godo.goH A D05-Aug-202113.8 KiB

godo_test.goH A D05-Aug-202118.8 KiB

image_actions.goH A D05-Aug-20212.6 KiB

image_actions_test.goH A D05-Aug-20212.4 KiB

images.goH A D05-Aug-20217.3 KiB

images_test.goH A D05-Aug-202110.1 KiB

invoices.goH A D05-Aug-20217 KiB

invoices_test.goH A D05-Aug-20218.4 KiB

keys.goH A D05-Aug-20216 KiB

keys_test.goH A D05-Aug-20216.5 KiB

kubernetes.goH A D05-Aug-202134.9 KiB

kubernetes_test.goH A D05-Aug-202147.1 KiB

links.goH A D05-Aug-20211.6 KiB

links_test.goH A D05-Aug-20213.8 KiB

load_balancers.goH A D05-Aug-202111.7 KiB

load_balancers_test.goH A D05-Aug-202122.9 KiB

meta.goH A D05-Aug-2021117

monitoring.goH A D05-Aug-20216.8 KiB

monitoring_test.goH A D05-Aug-202110.4 KiB

projects.goH A D05-Aug-20218.7 KiB

projects_test.goH A D05-Aug-202115.2 KiB

regions.goH A D05-Aug-20211.5 KiB

regions_test.goH A D05-Aug-20212.3 KiB

registry.goH A D05-Aug-202117.1 KiB

registry_test.goH A D05-Aug-202120.4 KiB

sizes.goH A D05-Aug-20211.8 KiB

sizes_test.goH A D05-Aug-20213.5 KiB

snapshots.goH A D05-Aug-20214 KiB

snapshots_test.goH A D05-Aug-20215.1 KiB

storage.goH A D05-Aug-20217.4 KiB

storage_actions.goH A D05-Aug-20214 KiB

storage_actions_test.goH A D05-Aug-20214.2 KiB

storage_test.goH A D05-Aug-202118.8 KiB

strings.goH A D05-Aug-20212.1 KiB

tags.goH A D05-Aug-20217.3 KiB

tags_test.goH A D05-Aug-202112.4 KiB

timestamp.goH A D05-Aug-2021829

timestamp_test.goH A D05-Aug-20215.2 KiB

vpcs.goH A D05-Aug-20217.1 KiB

vpcs_test.goH A D05-Aug-20219.6 KiB

README.md

1# Godo
2
3[![Build Status](https://travis-ci.org/digitalocean/godo.svg)](https://travis-ci.org/digitalocean/godo)
4[![GoDoc](https://godoc.org/github.com/digitalocean/godo?status.svg)](https://godoc.org/github.com/digitalocean/godo)
5
6Godo is a Go client library for accessing the DigitalOcean V2 API.
7
8You can view the client API docs here: [http://godoc.org/github.com/digitalocean/godo](http://godoc.org/github.com/digitalocean/godo)
9
10You can view DigitalOcean API docs here: [https://docs.digitalocean.com/reference/api/api-reference/](https://docs.digitalocean.com/reference/api/api-reference/)
11
12## Install
13```sh
14go get github.com/digitalocean/godo@vX.Y.Z
15```
16
17where X.Y.Z is the [version](https://github.com/digitalocean/godo/releases) you need.
18
19or
20```sh
21go get github.com/digitalocean/godo
22```
23for non Go modules usage or latest version.
24
25## Usage
26
27```go
28import "github.com/digitalocean/godo"
29```
30
31Create a new DigitalOcean client, then use the exposed services to
32access different parts of the DigitalOcean API.
33
34### Authentication
35
36Currently, Personal Access Token (PAT) is the only method of
37authenticating with the API. You can manage your tokens
38at the DigitalOcean Control Panel [Applications Page](https://cloud.digitalocean.com/settings/applications).
39
40You can then use your token to create a new client:
41
42```go
43package main
44
45import (
46    "github.com/digitalocean/godo"
47)
48
49func main() {
50    client := godo.NewFromToken("my-digitalocean-api-token")
51}
52```
53
54If you need to provide a `context.Context` to your new client, you should use [`godo.NewClient`](https://godoc.org/github.com/digitalocean/godo#NewClient) to manually construct a client instead.
55
56## Examples
57
58
59To create a new Droplet:
60
61```go
62dropletName := "super-cool-droplet"
63
64createRequest := &godo.DropletCreateRequest{
65    Name:   dropletName,
66    Region: "nyc3",
67    Size:   "s-1vcpu-1gb",
68    Image: godo.DropletCreateImage{
69        Slug: "ubuntu-20-04-x64",
70    },
71}
72
73ctx := context.TODO()
74
75newDroplet, _, err := client.Droplets.Create(ctx, createRequest)
76
77if err != nil {
78    fmt.Printf("Something bad happened: %s\n\n", err)
79    return err
80}
81```
82
83### Pagination
84
85If a list of items is paginated by the API, you must request pages individually. For example, to fetch all Droplets:
86
87```go
88func DropletList(ctx context.Context, client *godo.Client) ([]godo.Droplet, error) {
89    // create a list to hold our droplets
90    list := []godo.Droplet{}
91
92    // create options. initially, these will be blank
93    opt := &godo.ListOptions{}
94    for {
95        droplets, resp, err := client.Droplets.List(ctx, opt)
96        if err != nil {
97            return nil, err
98        }
99
100        // append the current page's droplets to our list
101        list = append(list, droplets...)
102
103        // if we are at the last page, break out the for loop
104        if resp.Links == nil || resp.Links.IsLastPage() {
105            break
106        }
107
108        page, err := resp.Links.CurrentPage()
109        if err != nil {
110            return nil, err
111        }
112
113        // set the page we want for the next request
114        opt.Page = page + 1
115    }
116
117    return list, nil
118}
119```
120
121## Versioning
122
123Each version of the client is tagged and the version is updated accordingly.
124
125To see the list of past versions, run `git tag`.
126
127
128## Documentation
129
130For a comprehensive list of examples, check out the [API documentation](https://docs.digitalocean.com/reference/api/api-reference/#tag/SSH-Keys).
131
132For details on all the functionality in this library, see the [GoDoc](http://godoc.org/github.com/digitalocean/godo) documentation.
133
134
135## Contributing
136
137We love pull requests! Please see the [contribution guidelines](CONTRIBUTING.md).
138