godo

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2014 License: BSD-3-Clause, MIT Imports: 12 Imported by: 0

README

GODO

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

Usage

import "github.com/digitaloceancloud/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 Digital Ocean Control Panel Applications Page.

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

import "code.google.com/p/goauth2/oauth"

pat := "mytoken"
t := &oauth.Transport{
	Token: &oauth.Token{AccessToken: pat},
}

client := godo.NewClient(t.Client())

Examples

Digital Ocean API Documentation

To list all Droplets your account has access to:

droplets, _, err := client.Droplet.List()
if err != nil {
	fmt.Printf("error: %v\n\n", err)
	return err
} else {
	fmt.Printf("%v\n\n", godo.Stringify(droplets))
}

To create a new Droplet:

dropletName := "super-cool-droplet"

createRequest := &godo.DropletCreateRequest{
	Name:   godo.String(dropletName),
	Region: godo.String("nyc2"),
	Size:   godo.String("512mb"),
	Image:  godo.Int(3240036), // ubuntu 14.04 64bit
}

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

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

Documentation

Overview

Package godo is the DigtalOcean API v2 client for Go

Index

Constants

View Source
const (

	// ActionInProgress is an in progress action status
	ActionInProgress = "in-progress"

	//ActionCompleted is a completed action status
	ActionCompleted = "completed"
)

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.

func Int

func Int(v int) *int

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.

func StreamToString

func StreamToString(stream io.Reader) string

StreamToString converts a reader to a string

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

func Stringify

func Stringify(message interface{}) string

Stringify attempts to create a string representation of Digital Ocean types

Types

type Action

type Action struct {
	ID           int        `json:"id"`
	Status       string     `json:"status"`
	Type         string     `json:"type"`
	StartedAt    *Timestamp `json:"started_at"`
	CompletedAt  *Timestamp `json:"completed_at"`
	ResourceID   int        `json:"resource_id"`
	ResourceType string     `json:"resource_type"`
}

Action represents a DigitalOcean Action

func (Action) String

func (a Action) String() string

type ActionRequest

type ActionRequest struct {
	Type   string                 `json:"type"`
	Params map[string]interface{} `json:"params,omitempty"`
}

ActionRequest reprents DigitalOcean Action Request

func (ActionRequest) String

func (d ActionRequest) String() string

Converts an ActionRequest to a string.

type ActionsService

type ActionsService struct {
	// contains filtered or unexported fields
}

ImageActionsService handles communition with the image action related methods of the DigitalOcean API.

func (*ActionsService) Get

func (s *ActionsService) Get(id int) (*Action, *Response, error)

func (*ActionsService) List

func (s *ActionsService) List() ([]Action, *Response, error)

List all actions

type Client

type Client struct {

	// Base URL for API requests.
	BaseURL *url.URL

	// User agent for client
	UserAgent string

	// Rate contains the current rate limit for the client as determined by the most recent
	// API call.
	Rate Rate

	// Services used for communicating with the API
	Actions        *ActionsService
	Domains        *DomainsService
	Droplet        *DropletsService
	DropletActions *DropletActionsService
	Images         *ImagesService
	ImageActions   *ImageActionsService
	Keys           *KeysService
	Regions        *RegionsService
	Sizes          *SizesService
	// contains filtered or unexported fields
}

Client manages communication with DigitalOcean V2 API.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new Digital Ocean API client.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response will be written to v, without attempting to decode it.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included in as the request body.

type DomainRecord

type DomainRecord struct {
	ID       int    `json:"id,float64,omitempty"`
	Type     string `json:"type,omitempty"`
	Name     string `json:"name,omitempty"`
	Data     string `json:"data,omitempty"`
	Priority int    `json:"priority,omitempty"`
	Port     int    `json:"port,omitempty"`
	Weight   int    `json:"weight,omitempty"`
}

DomainRecord represents a DigitalOcean DomainRecord

func (DomainRecord) String

func (d DomainRecord) String() string

Converts a DomainRecord to a string.

type DomainRecordEditRequest

type DomainRecordEditRequest struct {
	Type     string `json:"type,omitempty"`
	Name     string `json:"name,omitempty"`
	Data     string `json:"data,omitempty"`
	Priority int    `json:"priority,omitempty"`
	Port     int    `json:"port,omitempty"`
	Weight   int    `json:"weight,omitempty"`
}

DomainRecordEditRequest represents a request to update a domain record.

func (DomainRecordEditRequest) String

func (d DomainRecordEditRequest) String() string

Converts a DomainRecordEditRequest to a string.

type DomainRecordRoot

type DomainRecordRoot struct {
	DomainRecord *DomainRecord `json:"domain_record"`
}

type DomainRecordsOptions

type DomainRecordsOptions struct {
	ListOptions
}

type DomainRecordsRoot

type DomainRecordsRoot struct {
	DomainRecords []DomainRecord `json:"domain_records"`
}

type DomainsService

type DomainsService struct {
	// contains filtered or unexported fields
}

DomainsService handles communication wit the domain related methods of the DigitalOcean API.

func (*DomainsService) CreateRecord

func (s *DomainsService) CreateRecord(
	domain string,
	createRequest *DomainRecordEditRequest) (*DomainRecord, *Response, error)

CreateRecord creates a record using a DomainRecordEditRequest

func (*DomainsService) DeleteRecord

func (s *DomainsService) DeleteRecord(domain string, id int) (*Response, error)

DeleteRecord deletes a record from a domain identified by id

func (*DomainsService) EditRecord

func (s *DomainsService) EditRecord(
	domain string,
	id int,
	editRequest *DomainRecordEditRequest) (*DomainRecord, *Response, error)

EditRecord edits a record using a DomainRecordEditRequest

func (*DomainsService) Record

func (s *DomainsService) Record(domain string, id int) (*DomainRecord, *Response, error)

Record returns the record id from a domain

func (*DomainsService) Records

func (s *DomainsService) Records(domain string, opt *DomainRecordsOptions) ([]DomainRecord, *Response, error)

Records returns a slice of DomainRecords for a domain

type Droplet

type Droplet struct {
	ID          int       `json:"id,float64,omitempty"`
	Name        string    `json:"name,omitempty"`
	Memory      int       `json:"memory,omitempty"`
	Vcpus       int       `json:"vcpus,omitempty"`
	Disk        int       `json:"disk,omitempty"`
	Region      *Region   `json:"region,omitempty"`
	Image       *Image    `json:"image,omitempty"`
	Size        *Size     `json:"size,omitempty"`
	BackupIDs   []int     `json:"backup_ids,omitempty"`
	SnapshotIDs []int     `json:"snapshot_ids,omitempty"`
	Locked      bool      `json:"locked,bool,omitempty"`
	Status      string    `json:"status,omitempty"`
	Networks    *Networks `json:"networks,omitempty"`
	ActionIDs   []int     `json:"action_ids,omitempty"`
}

Droplet represents a DigitalOcean Droplet

func (Droplet) String

func (d Droplet) String() string

Convert Droplet to a string

type DropletActionsService

type DropletActionsService struct {
	// contains filtered or unexported fields
}

DropletActionsService handles communication with the droplet action related methods of the DigitalOcean API.

func (*DropletActionsService) Get

func (s *DropletActionsService) Get(dropletID, actionID int) (*Action, *Response, error)

Get an action for a particular droplet by id.

func (*DropletActionsService) GetByURI

func (s *DropletActionsService) GetByURI(rawurl string) (*Action, *Response, error)

GetByURI gets an action for a particular droplet by id.

func (*DropletActionsService) PowerCycle

func (s *DropletActionsService) PowerCycle(id int) (*Action, *Response, error)

PowerCycle a Droplet

func (*DropletActionsService) PowerOff

func (s *DropletActionsService) PowerOff(id int) (*Action, *Response, error)

PowerOff a Droplet

func (*DropletActionsService) Reboot

func (s *DropletActionsService) Reboot(id int) (*Action, *Response, error)

Reboot a Droplet

func (*DropletActionsService) Rename

func (s *DropletActionsService) Rename(id int, name string) (*Action, *Response, error)

Rename a Droplet

func (*DropletActionsService) Resize

func (s *DropletActionsService) Resize(id int, sizeSlug string) (*Action, *Response, error)

Resize a Droplet

func (*DropletActionsService) Restore

func (s *DropletActionsService) Restore(id, imageID int) (*Action, *Response, error)

Restore an image to a Droplet

func (*DropletActionsService) Shutdown

func (s *DropletActionsService) Shutdown(id int) (*Action, *Response, error)

Shutdown a Droplet

type DropletCreateRequest

type DropletCreateRequest struct {
	Name    string        `json:"name"`
	Region  string        `json:"region"`
	Size    string        `json:"size"`
	Image   string        `json:"image"`
	SSHKeys []interface{} `json:"ssh_keys"`
}

DropletCreateRequest represents a request to create a droplet.

func (DropletCreateRequest) String

func (d DropletCreateRequest) String() string

type DropletRoot

type DropletRoot struct {
	Droplet *Droplet `json:"droplet"`
	Links   *Links   `json:"links,omitempty"`
}

DropletRoot represents a Droplet root

type DropletsService

type DropletsService struct {
	// contains filtered or unexported fields
}

DropletsService handles communication with the droplet related methods of the DigitalOcean API.

func (*DropletsService) Create

func (s *DropletsService) Create(createRequest *DropletCreateRequest) (*DropletRoot, *Response, error)

Create droplet

func (*DropletsService) Delete

func (s *DropletsService) Delete(dropletID int) (*Response, error)

Delete droplet

func (*DropletsService) Get

func (s *DropletsService) Get(dropletID int) (*DropletRoot, *Response, error)

Get individual droplet

func (*DropletsService) List

func (s *DropletsService) List() ([]Droplet, *Response, error)

List all droplets

type ErrorResponse

type ErrorResponse struct {
	// HTTP response that caused this error
	Response *http.Response

	// Error message
	Message string
}

An ErrorResponse reports the error caused by an API request

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Image

type Image struct {
	ID           int      `json:"id,float64,omitempty"`
	Name         string   `json:"name,omitempty"`
	Distribution string   `json:"distribution,omitempty"`
	Slug         string   `json:"slug,omitempty"`
	Public       bool     `json:"public,omitempty"`
	Regions      []string `json:"regions,omitempty"`
}

Image represents a DigitalOcean Image

func (Image) String

func (i Image) String() string

type ImageActionsService

type ImageActionsService struct {
	// contains filtered or unexported fields
}

ImageActionsService handles communition with the image action related methods of the DigitalOcean API.

func (*ImageActionsService) Get

func (i *ImageActionsService) Get(imageID, actionID int) (*Action, *Response, error)

Get an action for a particular image by id.

func (*ImageActionsService) Transfer

func (i *ImageActionsService) Transfer(imageID int, transferRequest *ActionRequest) (*Action, *Response, error)

Transfer an image

type ImagesService

type ImagesService struct {
	// contains filtered or unexported fields
}

ImagesService handles communication with the image related methods of the DigitalOcean API.

func (*ImagesService) List

func (s *ImagesService) List() ([]Image, *Response, error)

List all sizes

type Key

type Key struct {
	ID          int    `json:"id,float64,omitempty"`
	Name        string `json:"name,omitempty"`
	Fingerprint string `json:"fingerprint,omitempty"`
	PublicKey   string `json:"public_key,omitempty"`
}

Key represents a DigitalOcean Key.

func (Key) String

func (s Key) String() string

type KeyCreateRequest

type KeyCreateRequest struct {
	Name      string `json:"name"`
	PublicKey string `json:"public_key"`
}

KeyCreateRequest represents a request to create a new key.

type KeysService

type KeysService struct {
	// contains filtered or unexported fields
}

KeysService handles communication with key related method of the DigitalOcean API.

func (*KeysService) Create

func (s *KeysService) Create(createRequest *KeyCreateRequest) (*Key, *Response, error)

Create a key using a KeyCreateRequest

func (*KeysService) DeleteByFingerprint

func (s *KeysService) DeleteByFingerprint(fingerprint string) (*Response, error)

DeleteByFingerprint deletes a key by its fingerprint

func (*KeysService) DeleteByID

func (s *KeysService) DeleteByID(keyID int) (*Response, error)

DeleteByID deletes a key by its id

func (*KeysService) GetByFingerprint

func (s *KeysService) GetByFingerprint(fingerprint string) (*Key, *Response, error)

GetByFingerprint gets a Key by by fingerprint

func (*KeysService) GetByID

func (s *KeysService) GetByID(keyID int) (*Key, *Response, error)

GetByID gets a Key by id

func (*KeysService) List

func (s *KeysService) List() ([]Key, *Response, error)

List all keys

type Link struct {
	ID   int    `json:"id,omitempty"`
	Rel  string `json:"rel,omitempty"`
	HREF string `json:"href,omitempty"`
}

Link represents a link

type Links struct {
	Actions []Link `json:"actions,omitempty"`
}

Links are extra links for a droplet

func (*Links) Action

func (l *Links) Action(action string) *Link

Action extracts Link

type ListOptions

type ListOptions struct {
	// For paginated result sets, page of results to retrieve.
	Page int `url:"page,omitempty"`

	// For paginated result sets, the number of results to include per page.
	PerPage int `url:"per_page,omitempty"`
}

ListOptions specifies the optional parameters to various List methods that support pagination.

type Network

type Network struct {
	IPAddress string `json:"ip_address,omitempty"`
	Netmask   string `json:"netmask,omitempty"`
	Gateway   string `json:"gateway,omitempty"`
	Type      string `json:"type,omitempty"`
}

Network represents a DigitalOcean Network

func (Network) String

func (n Network) String() string

type Networks

type Networks struct {
	V4 []Network `json:"v4,omitempty"`
	V6 []Network `json:"v6,omitempty"`
}

Networks represents the droplet's networks

type Rate

type Rate struct {
	// The number of request per hour the client is currently limited to.
	Limit int `json:"limit"`

	// The number of remaining requests the client can make this hour.
	Remaining int `json:"remaining"`

	// The time at w\hic the current rate limit will reset.
	Reset Timestamp `json:"reset"`
}

Rate contains the rate limit for the current client.

func (Rate) String

func (r Rate) String() string

type Region

type Region struct {
	Slug      string   `json:"slug,omitempty"`
	Name      string   `json:"name,omitempty"`
	Sizes     []string `json:"sizes,omitempty"`
	Available bool     `json:"available,omitempty`
}

Region represents a DigitalOcean Region

func (Region) String

func (r Region) String() string

type RegionsService

type RegionsService struct {
	// contains filtered or unexported fields
}

RegionsService handles communication with the region related methods of the DigitalOcean API.

func (*RegionsService) List

func (s *RegionsService) List() ([]Region, *Response, error)

List all regions

type Response

type Response struct {
	*http.Response

	NextPage  string
	PrevPage  string
	FirstPage string
	LastPage  string

	// Monitoring URI
	Monitor string

	Rate
}

Response is a Digital Ocean response. This wraps the standard http.Response returned from DigitalOcean.

type Size

type Size struct {
	Slug         string   `json:"slug,omitempty"`
	Memory       int      `json:"memory,omitempty"`
	Vcpus        int      `json:"vcpus,omitempty"`
	Disk         int      `json:"disk,omitempty"`
	PriceMonthly float64  `json:"price_monthly,omitempty"`
	PriceHourly  float64  `json:"price_hourly,omitempty"`
	Regions      []string `json:"regions,omitempty"`
}

Size represents a DigitalOcean Size

func (Size) String

func (s Size) String() string

type SizesService

type SizesService struct {
	// contains filtered or unexported fields
}

SizesService handles communication with the size related methods of the DigitalOcean API.

func (*SizesService) List

func (s *SizesService) List() ([]Size, *Response, error)

List all images

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp represents a time that can be unmarshalled from a JSON string formatted as either an RFC3339 or Unix timestamp. All exported methods of time.Time can be called on Timestamp.

func (Timestamp) Equal

func (t Timestamp) Equal(u Timestamp) bool

Equal reports whether t and u are equal based on time.Equal

func (Timestamp) String

func (t Timestamp) String() string

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface. Time is expected in RFC3339 or Unix format.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL