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"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/digitalocean/godo"
|
|
||||||
"github.com/wtfutil/wtf/utils"
|
"github.com/wtfutil/wtf/utils"
|
||||||
"github.com/wtfutil/wtf/view"
|
"github.com/wtfutil/wtf/view"
|
||||||
)
|
)
|
||||||
|
|
||||||
type dropletPropertiesTable struct {
|
type dropletPropertiesTable struct {
|
||||||
droplet *godo.Droplet
|
droplet *Droplet
|
||||||
propertyMap map[string]string
|
propertyMap map[string]string
|
||||||
|
|
||||||
colWidth0 int
|
colWidth0 int
|
||||||
@ -20,7 +19,7 @@ type dropletPropertiesTable struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newDropletPropertiesTable creates and returns an instance of DropletPropertiesTable
|
// newDropletPropertiesTable creates and returns an instance of DropletPropertiesTable
|
||||||
func newDropletPropertiesTable(droplet *godo.Droplet) *dropletPropertiesTable {
|
func newDropletPropertiesTable(droplet *Droplet) *dropletPropertiesTable {
|
||||||
propTable := &dropletPropertiesTable{
|
propTable := &dropletPropertiesTable{
|
||||||
droplet: droplet,
|
droplet: droplet,
|
||||||
|
|
||||||
|
@ -35,10 +35,11 @@ type Widget struct {
|
|||||||
|
|
||||||
app *tview.Application
|
app *tview.Application
|
||||||
client *godo.Client
|
client *godo.Client
|
||||||
droplets []godo.Droplet
|
droplets []*Droplet
|
||||||
pages *tview.Pages
|
pages *tview.Pages
|
||||||
settings *Settings
|
settings *Settings
|
||||||
err error
|
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWidget creates a new instance of a widget
|
// NewWidget creates a new instance of a widget
|
||||||
@ -127,7 +128,7 @@ func (widget *Widget) createClient() {
|
|||||||
|
|
||||||
// currentDroplet returns the currently-selected droplet, if there is one
|
// currentDroplet returns the currently-selected droplet, if there is one
|
||||||
// Returns nil if no droplet is selected
|
// Returns nil if no droplet is selected
|
||||||
func (widget *Widget) currentDroplet() *godo.Droplet {
|
func (widget *Widget) currentDroplet() *Droplet {
|
||||||
if len(widget.droplets) == 0 {
|
if len(widget.droplets) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -136,21 +137,24 @@ func (widget *Widget) currentDroplet() *godo.Droplet {
|
|||||||
return nil
|
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
|
// dropletsFetch uses the DigitalOcean API to fetch information about all the available droplets
|
||||||
func (widget *Widget) dropletsFetch() ([]godo.Droplet, error) {
|
func (widget *Widget) dropletsFetch() ([]*Droplet, error) {
|
||||||
dropletList := []godo.Droplet{}
|
dropletList := []*Droplet{}
|
||||||
opts := &godo.ListOptions{}
|
opts := &godo.ListOptions{}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
droplets, resp, err := widget.client.Droplets.List(context.Background(), opts)
|
doDroplets, resp, err := widget.client.Droplets.List(context.Background(), opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return dropletList, err
|
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() {
|
if resp.Links == nil || resp.Links.IsLastPage() {
|
||||||
break
|
break
|
||||||
|
Loading…
x
Reference in New Issue
Block a user