github.com/wtfutil/wtf@v0.43.0/modules/digitalocean/droplet.go (about) 1 package digitalocean 2 3 import ( 4 "strings" 5 6 "github.com/digitalocean/godo" 7 "github.com/wtfutil/wtf/utils" 8 ) 9 10 // Droplet represents WTF's view of a DigitalOcean droplet 11 type Droplet struct { 12 godo.Droplet 13 14 Image godo.Image 15 Region godo.Region 16 } 17 18 // NewDroplet creates and returns an instance of Droplet 19 func NewDroplet(doDroplet godo.Droplet) *Droplet { 20 return &Droplet{ 21 doDroplet, 22 *doDroplet.Image, 23 *doDroplet.Region, 24 } 25 } 26 27 /* -------------------- Exported Functions -------------------- */ 28 29 // StringValueForProperty returns a string value for the given column 30 func (drop *Droplet) StringValueForProperty(propName string) (string, error) { 31 // Figure out if we should forward this property to a sub-object 32 // Lets us support "Region.Name" column definitions 33 split := strings.Split(propName, ".") 34 35 switch split[0] { 36 case "Image": 37 return utils.StringValueForProperty(drop.Image, split[1]) 38 case "Region": 39 return utils.StringValueForProperty(drop.Region, split[1]) 40 default: 41 return utils.StringValueForProperty(drop, propName) 42 } 43 }