diff options
| author | Jeff Carr <[email protected]> | 2023-12-29 01:36:10 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2023-12-29 01:36:10 -0600 |
| commit | 1258be9beff2e45c94ba5f7c29db65be02a1e2d4 (patch) | |
| tree | c1b6bc4e9a648835ec243140fd29689db1cf0bf1 /digitalocean/listDroplets.go | |
| parent | 8afc73da048204f4245e0c850436c1e3e70055a5 (diff) | |
add digital ocean & DNS state windows
lists digital ocean droplets
create a new digital ocean droplet
knows what needs to be done to get IPv4 and IPv6 to work
update windows on Show()
make a window for the state of DNS specific to the hostname
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'digitalocean/listDroplets.go')
| -rw-r--r-- | digitalocean/listDroplets.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/digitalocean/listDroplets.go b/digitalocean/listDroplets.go new file mode 100644 index 0000000..a46be29 --- /dev/null +++ b/digitalocean/listDroplets.go @@ -0,0 +1,49 @@ +package digitalocean + +import ( + "context" + "fmt" + + "golang.org/x/oauth2" + + "github.com/digitalocean/godo" +) + +// ListDroplets fetches and prints out the droplets along with their IPv4 and IPv6 addresses. +func ListDroplets(token string) error { + // OAuth token for authentication. + tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token}) + + // OAuth2 client. + oauthClient := oauth2.NewClient(context.Background(), tokenSource) + + // DigitalOcean client. + client := godo.NewClient(oauthClient) + + // Context. + ctx := context.TODO() + + // List all droplets. + droplets, _, err := client.Droplets.List(ctx, &godo.ListOptions{}) + if err != nil { + return err + } + + // Iterate over droplets and print their details. + for _, droplet := range droplets { + fmt.Printf("Droplet: %s\n", droplet.Name) + for _, network := range droplet.Networks.V4 { + if network.Type == "public" { + fmt.Printf("IPv4: %s\n", network.IPAddress) + } + } + for _, network := range droplet.Networks.V6 { + if network.Type == "public" { + fmt.Printf("IPv6: %s\n", network.IPAddress) + } + } + fmt.Println("-------------------------") + } + + return nil +} |
