Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
List DigitalOcean snapshots using godo
package main
import "os"
import "fmt"
import "golang.org/x/oauth2"
import "github.com/digitalocean/godo"
type TokenSource struct {
AccessToken string
}
func (t *TokenSource) Token() (*oauth2.Token, error) {
token := &oauth2.Token{
AccessToken: t.AccessToken,
}
return token, nil
}
func main() {
pat := os.Getenv("DO_TOKEN")
tokenSource := &TokenSource{
AccessToken: pat,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
opt := &godo.ListOptions{
Page: 1,
PerPage: 200,
}
vol, _, err := client.Snapshots.ListVolume(opt)
if err != nil {
fmt.Printf("Something bad happened: %s\n\n", err)
} else {
fmt.Printf("Volumes:\n%v\n\n", godo.Stringify(vol))
}
drop, _, err := client.Snapshots.ListDroplet(opt)
if err != nil {
fmt.Printf("Something bad happened: %s\n\n", err)
} else {
fmt.Printf("Droplets:\n%v\n\n", godo.Stringify(drop))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.