Categorygithub.com/senorprogrammer/godo
modulepackage
0.9.0
Repository: https://github.com/senorprogrammer/godo.git
Documentation: pkg.go.dev

# README

Build Status

Godo

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/

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:

import "golang.org/x/oauth2"

pat := "mytoken"
type TokenSource struct {
    AccessToken string
}

func (t *TokenSource) Token() (*oauth2.Token, error) {
    token := &oauth2.Token{
        AccessToken: t.AccessToken,
    }
    return token, nil
}

tokenSource := &TokenSource{
    AccessToken: pat,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)

Examples

To create a new Droplet:

dropletName := "super-cool-droplet"

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

newDroplet, _, err := client.Droplets.Create(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(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(opt)
        if err != nil {
            return nil, err
        }

        // append the current page's droplets to our list
        for _, d := range droplets {
            list = append(list, d)
        }

        // 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.

Since Go does not have a built-in versioning, a package management tool is recommended - a good one that works with git tags is gopkg.in.

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.

# Packages

No description provided by the author

# Functions

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.
CheckResponse checks the API response for errors, and returns them if present.
Int is a helper routine that allocates a new int32 value to store v and returns a pointer to it, but unlike Int32 its argument value is an int.
NewArgError creates an InputError.
NewClient returns a new DigitalOcean API client.
StreamToString converts a reader to a string.
String is a helper routine that allocates a new string value to store v and returns a pointer to it.
Stringify attempts to create a string representation of DigitalOcean types.

# Constants

ActionCompleted is a completed action status.
ActionInProgress is an in progress action status.

# Structs

Account represents a DigitalOcean Account.
AccountServiceOp handles communication with the Account related methods of the DigitalOcean API.
Action represents a DigitalOcean Action.
ActionsServiceOp handles communition with the image action related methods of the DigitalOcean API.
ArgError is an error that represents an error with an input to godo.
Client manages communication with DigitalOcean V2 API.
Domain represents a DigitalOcean domain.
DomainCreateRequest respresents a request to create a domain.
DomainRecord represents a DigitalOcean DomainRecord.
DomainRecordEditRequest represents a request to update a domain record.
DomainsServiceOp handles communication with the domain related methods of the DigitalOcean API.
Droplet represents a DigitalOcean Droplet.
DropletActionsServiceOp handles communication with the droplet action related methods of the DigitalOcean API.
DropletCreateImage identifies an image for the create request.
DropletCreateRequest represents a request to create a droplet.
DropletCreateSSHKey identifies a SSH Key for the create request.
DropletsServiceOp handles communication with the droplet related methods of the DigitalOcean API.
An ErrorResponse reports the error caused by an API request.
Image represents a DigitalOcean Image.
ImageActionsServiceOp handles communition with the image action related methods of the DigitalOcean API.
ImagesServiceOp handles communication with the image related methods of the DigitalOcean API.
ImageUpdateRequest represents a request to update an image.
Kernel object.
Key represents a DigitalOcean Key.
KeyCreateRequest represents a request to create a new key.
KeysServiceOp handles communication with key related method of the DigitalOcean API.
KeyUpdateRequest represents a request to update a DigitalOcean key.
LinkAction is a pointer to an action.
Links manages links that are returned along with a List.
ListOptions specifies the optional parameters to various List methods that support pagination.
Networks represents the droplet's networks.
NetworkV4 represents a DigitalOcean IPv4 Network.
NetworkV6 represents a DigitalOcean IPv6 network.
Pages are pages specified in Links.
Rate contains the rate limit for the current client.
Region represents a DigitalOcean Region.
RegionsServiceOp handles communication with the region related methods of the DigitalOcean API.
Response is a DigitalOcean response.
Size represents a DigitalOcean Size.
SizesServiceOp handles communication with the size related methods of the DigitalOcean API.
Timestamp represents a time that can be unmarshalled from a JSON string formatted as either an RFC3339 or Unix timestamp.

# Interfaces

AccountService is an interface for interfacing with the Account endpoints of the DigitalOcean API See: https://developers.digitalocean.com/documentation/v2/#account.
ActionsService handles communction with action related methods of the DigitalOcean API: https://developers.digitalocean.com/documentation/v2#actions.
DomainsService is an interface for managing DNS with the DigitalOcean API.
DropletActionsService is an interface for interfacing with the droplet actions endpoints of the DigitalOcean API See: https://developers.digitalocean.com/documentation/v2#droplet-actions.
DropletsService is an interface for interfacing with the droplet endpoints of the DigitalOcean API See: https://developers.digitalocean.com/documentation/v2#droplets.
ImageActionsService is an interface for interfacing with the image actions endpoints of the DigitalOcean API See: https://developers.digitalocean.com/documentation/v2#image-actions.
ImagesService is an interface for interfacing with the images endpoints of the DigitalOcean API See: https://developers.digitalocean.com/documentation/v2#images.
KeysService is an interface for interfacing with the keys endpoints of the DigitalOcean API See: https://developers.digitalocean.com/documentation/v2#keys.
RegionsService is an interface for interfacing with the regions endpoints of the DigitalOcean API See: https://developers.digitalocean.com/documentation/v2#regions.
SizesService is an interface for interfacing with the size endpoints of the DigitalOcean API See: https://developers.digitalocean.com/documentation/v2#sizes.

# Type aliases

ActionRequest reprents DigitalOcean Action Request.
RequestCompletionCallback defines the type of the request callback function.