mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-986 Wrap the DigitalOcean droplet in our own droplet
This gives us something to build off while still providing the underlying functionality of the original droplet instance. Signed-off-by: Chris Cummer <chriscummer@me.com>
This commit is contained in:
parent
b2e0c520e8
commit
db997b9a73
17
modules/digitalocean/droplet.go
Normal file
17
modules/digitalocean/droplet.go
Normal file
@ -0,0 +1,17 @@
|
||||
package digitalocean
|
||||
|
||||
import "github.com/digitalocean/godo"
|
||||
|
||||
// Droplet represents WTF's view of a DigitalOcean droplet
|
||||
type Droplet struct {
|
||||
godo.Droplet
|
||||
}
|
||||
|
||||
// NewDroplet creates and returns an instance of Droplet
|
||||
func NewDroplet(doDroplet godo.Droplet) *Droplet {
|
||||
droplet := &Droplet{
|
||||
doDroplet,
|
||||
}
|
||||
|
||||
return droplet
|
||||
}
|
@ -5,13 +5,12 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/digitalocean/godo"
|
||||
"github.com/wtfutil/wtf/utils"
|
||||
"github.com/wtfutil/wtf/view"
|
||||
)
|
||||
|
||||
type dropletPropertiesTable struct {
|
||||
droplet *godo.Droplet
|
||||
droplet *Droplet
|
||||
propertyMap map[string]string
|
||||
|
||||
colWidth0 int
|
||||
@ -20,7 +19,7 @@ type dropletPropertiesTable struct {
|
||||
}
|
||||
|
||||
// newDropletPropertiesTable creates and returns an instance of DropletPropertiesTable
|
||||
func newDropletPropertiesTable(droplet *godo.Droplet) *dropletPropertiesTable {
|
||||
func newDropletPropertiesTable(droplet *Droplet) *dropletPropertiesTable {
|
||||
propTable := &dropletPropertiesTable{
|
||||
droplet: droplet,
|
||||
|
||||
|
@ -35,9 +35,10 @@ type Widget struct {
|
||||
|
||||
app *tview.Application
|
||||
client *godo.Client
|
||||
droplets []godo.Droplet
|
||||
droplets []*Droplet
|
||||
pages *tview.Pages
|
||||
settings *Settings
|
||||
|
||||
err error
|
||||
}
|
||||
|
||||
@ -127,7 +128,7 @@ func (widget *Widget) createClient() {
|
||||
|
||||
// currentDroplet returns the currently-selected droplet, if there is one
|
||||
// Returns nil if no droplet is selected
|
||||
func (widget *Widget) currentDroplet() *godo.Droplet {
|
||||
func (widget *Widget) currentDroplet() *Droplet {
|
||||
if len(widget.droplets) == 0 {
|
||||
return nil
|
||||
}
|
||||
@ -136,21 +137,24 @@ func (widget *Widget) currentDroplet() *godo.Droplet {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &widget.droplets[widget.Selected]
|
||||
return widget.droplets[widget.Selected]
|
||||
}
|
||||
|
||||
// dropletsFetch uses the DigitalOcean API to fetch information about all the available droplets
|
||||
func (widget *Widget) dropletsFetch() ([]godo.Droplet, error) {
|
||||
dropletList := []godo.Droplet{}
|
||||
func (widget *Widget) dropletsFetch() ([]*Droplet, error) {
|
||||
dropletList := []*Droplet{}
|
||||
opts := &godo.ListOptions{}
|
||||
|
||||
for {
|
||||
droplets, resp, err := widget.client.Droplets.List(context.Background(), opts)
|
||||
doDroplets, resp, err := widget.client.Droplets.List(context.Background(), opts)
|
||||
if err != nil {
|
||||
return dropletList, err
|
||||
}
|
||||
|
||||
dropletList = append(dropletList, droplets...)
|
||||
for _, doDroplet := range doDroplets {
|
||||
droplet := NewDroplet(doDroplet)
|
||||
dropletList = append(dropletList, droplet)
|
||||
}
|
||||
|
||||
if resp.Links == nil || resp.Links.IsLastPage() {
|
||||
break
|
||||
|
Loading…
x
Reference in New Issue
Block a user