To use GoCenter:
export GOPROXY=https://gocenter.io
bitbucket.org/pkg/ocean
January 1st 0001
Last Modified
0
Stars
Unknown
License
6
Downloads
ReadMe
Mod File
GoDocs
New
Security
Dependencies (0)
Used By (0)
Metrics
Versions
ocean
Digital Ocean v2 API client package for Go (golang).
Status
Digital Ocean’s v2 endpoint is still in beta so things might break.
Quick Tour
First you’ll need to create a client…
import "bitbucket.org/pkg/ocean"
var client = ocean.NewClient("...YOUR API KEY...")
Then you can interact with the API…
// Get required size.
size, err := client.Size("512mb")
if err != nil {
t.Fatal(err)
}
// Get a region.
region,err := client.Region("lon1")
if err != nil {
t.Fatal(err)
}
// Get stock image.
img, err := client.Image("ubuntu-14-04-x32")
if err != nil {
t.Fatal(err)
}
// Get ssh keys.
keys, err := client.Keys()
if err != nil {
t.Fatal(err)
}
// Create a new droplet.
d, err := client.NewDroplet(&ocean.DropletConfig{
Name: "test",
Region: region,
Size: size,
Image: img,
Keys: keys,
Backups: false,
PrivateNetworking: true,
UserData: ``,
Ipv6: true,
})
if err != nil {
t.Fatal(err)
}
// Perform a reboot.
task, err := d.Reboot()
if err != nil {
t.Fatal(err)
}
// Wait for task to complete.
err = task.Wait()
if err != nil {
t.Fatal(err)
}
// Remove the droplet.
err = d.Destroy()
if err != nil {
t.Fatal(err)
}
A note on Actions
Use the Wait()
method on actions to block until the action is complete.
Methods that perform actions (like droplet.Reboot()
) will block if there are any pending actions.
Documenation
See godoc
Example
There’s an example cli tool in the ./examples dir.