diff options
| author | Jeff Carr <[email protected]> | 2023-12-31 05:48:29 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2023-12-31 05:48:29 -0600 |
| commit | c5ff4637fb1a5eb1c8910d946b4fc97a8bc55c9b (patch) | |
| tree | 97284ed1f0cdc7305539f3d83bf41db7a39b5e0b /digitalocean/api.go | |
| parent | d2f0691744ff677a3d044cad72c1c35d32f85d92 (diff) | |
droplet create has region
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'digitalocean/api.go')
| -rw-r--r-- | digitalocean/api.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/digitalocean/api.go b/digitalocean/api.go new file mode 100644 index 0000000..b1568b1 --- /dev/null +++ b/digitalocean/api.go @@ -0,0 +1,36 @@ +package digitalocean + +import ( + "context" + + "golang.org/x/oauth2" + "github.com/digitalocean/godo" + + "go.wit.com/log" +) + +func (d *DigitalOcean) listRegions() []godo.Region { + tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: d.token}) + oauthClient := oauth2.NewClient(context.Background(), tokenSource) + client := godo.NewClient(oauthClient) + + ctx := context.TODO() + + // Retrieve all regions. + regions, _, err := client.Regions.List(ctx, &godo.ListOptions{}) + if err != nil { + d.err = err + log.Warn(err, "digitalocean.listRegions() failed") + return nil + } + + /* + // Print details of each region. + fmt.Println("Available Regions:") + for _, region := range regions { + fmt.Printf("Slug: %s, Name: %s, Available: %v\n", region.Slug, region.Name, region.Available) + } + */ + + return regions +} |
