diff --git a/Makefile b/Makefile index 83afa97..4dc6b96 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,9 @@ all: @echo a work in progress digital ocean control panel @echo +goimports: + goimports -w *.go + redomod: rm -f go.* GO111MODULE= go mod init diff --git a/api.go b/api.go index b1568b1..fb3118e 100644 --- a/api.go +++ b/api.go @@ -3,8 +3,8 @@ package digitalocean import ( "context" - "golang.org/x/oauth2" "github.com/digitalocean/godo" + "golang.org/x/oauth2" "go.wit.com/log" ) @@ -25,11 +25,11 @@ func (d *DigitalOcean) listRegions() []godo.Region { } /* - // 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) - } + // 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 diff --git a/args.go b/args.go index ffc4376..e07355c 100644 --- a/args.go +++ b/args.go @@ -3,7 +3,7 @@ package digitalocean // initializes logging and command line options import ( - "go.wit.com/arg" + "go.wit.com/dev/alexflint/arg" "go.wit.com/log" ) @@ -19,10 +19,10 @@ type ArgsDo struct { func init() { arg.Register(&argDo) - full := "go.wit.com/gui/digitalocean" + full := "go.wit.com/lib/gui/digitalocean" short := "DOgui" - NOW = log.NewFlag( "NOW", true, full, short, "temp debugging stuff") + NOW = log.NewFlag("NOW", true, full, short, "temp debugging stuff") INFO = log.NewFlag("INFO", false, full, short, "normal debugging stuff") INFO = log.NewFlag("POLL", false, full, short, "show droplet status polling") } diff --git a/create.go b/create.go index dfd12e3..85634e2 100644 --- a/create.go +++ b/create.go @@ -3,11 +3,12 @@ package digitalocean import ( "context" "strings" - "golang.org/x/oauth2" - "github.com/digitalocean/godo" + "github.com/digitalocean/godo" + "golang.org/x/oauth2" + + "go.wit.com/lib/gadgets" "go.wit.com/log" - "go.wit.com/gui/gadgets" // "go.wit.com/gui" ) @@ -78,12 +79,12 @@ func (d *DigitalOcean) createDropletNew(name, region, size, image string) (*godo log.Verbose("found ssh key.Fingerprint =", key.Fingerprint) log.Verbose("found ssh key:", key) /* - sshKeys = []godo.DropletCreateSSHKey{ - {ID: key.ID}, - } + sshKeys = []godo.DropletCreateSSHKey{ + {ID: key.ID}, + } */ sshKeys = append(sshKeys, godo.DropletCreateSSHKey{ID: key.ID}) - } + } // Define the create request. createRequest := &godo.DropletCreateRequest{ @@ -93,7 +94,7 @@ func (d *DigitalOcean) createDropletNew(name, region, size, image string) (*godo Image: godo.DropletCreateImage{ Slug: image, }, - IPv6: true, // Enable IPv6 + IPv6: true, // Enable IPv6 SSHKeys: sshKeys, // Add SSH key IDs here } @@ -114,7 +115,9 @@ var myCreate *windowCreate // This is initializes the main DO object // You can only have one of these func InitCreateWindow() *windowCreate { - if ! myDo.Ready() {return nil} + if !myDo.Ready() { + return nil + } if myCreate != nil { myCreate.Show() return myCreate @@ -127,7 +130,7 @@ func InitCreateWindow() *windowCreate { // make a group label and a grid myCreate.group = myCreate.window.NewGroup("droplets:").Pad() myCreate.grid = myCreate.group.NewGrid("grid", 2, 1).Pad() - + myCreate.name = gadgets.NewBasicEntry(myCreate.grid, "Name").Set("test.wit.com") myCreate.region = gadgets.NewBasicDropdown(myCreate.grid, "Region") @@ -143,7 +146,7 @@ func InitCreateWindow() *windowCreate { log.Info("Skipping region. No available sizes region =", region.Name) } else { s := region.Name + " (" + region.Slug + ")" - if (myCreate.regionSlug == "") { + if myCreate.regionSlug == "" { myCreate.regionSlug = region.Slug } myCreate.region.Add(s) @@ -205,15 +208,15 @@ func InitCreateWindow() *windowCreate { // box := myCreate.group.NewBox("vBox", false).Pad() box := myCreate.group.NewBox("hBox", true).Pad() - box.NewButton("Cancel", func () { + box.NewButton("Cancel", func() { myCreate.Hide() }) - box.NewButton("Create", func () { + box.NewButton("Create", func() { name := myCreate.name.Get() size := myCreate.size.Get() region := myCreate.regionSlug image := myCreate.image.Get() - if (region == "") { + if region == "" { log.Info("Create() droplet name =", name, "region =", region, "size =", size, "image", image) log.Info("Create() region lookup failed") return @@ -230,7 +233,9 @@ func InitCreateWindow() *windowCreate { // Find the size func (d *windowCreate) UpdateSize() { - if ! d.Ready() {return} + if !d.Ready() { + return + } log.Info("Now find the size. sizes count =", len(myCreate.regionSelected.Sizes)) var s string m := myCreate.memory.Get() @@ -270,12 +275,16 @@ func (d *windowCreate) UpdateSize() { // Returns true if the status is valid func (d *windowCreate) Ready() bool { - if d == nil {return false} + if d == nil { + return false + } return d.ready } func (d *windowCreate) Show() { - if ! d.Ready() {return} + if !d.Ready() { + return + } log.Info("digitalocean.Show() window") if d.hidden { d.window.Show() @@ -284,9 +293,11 @@ func (d *windowCreate) Show() { } func (d *windowCreate) Hide() { - if ! d.Ready() {return} + if !d.Ready() { + return + } log.Info("digitalocean.Hide() window") - if ! d.hidden { + if !d.hidden { d.window.Hide() } d.hidden = true diff --git a/droplet.go b/droplet.go index 01913cc..efabe95 100644 --- a/droplet.go +++ b/droplet.go @@ -1,10 +1,11 @@ package digitalocean -import ( +import ( "errors" "sort" - "strings" "strconv" + "strings" + "github.com/digitalocean/godo" "go.wit.com/log" @@ -12,10 +13,12 @@ import ( ) func (d *DigitalOcean) NewDroplet(dd *godo.Droplet) *Droplet { - if ! myDo.Ready() {return nil} + if !myDo.Ready() { + return nil + } // check if the droplet ID already exists - if (d.dropMap[dd.ID] != nil) { + if d.dropMap[dd.ID] != nil { log.Error(errors.New("droplet.NewDroplet() already exists")) return d.dropMap[dd.ID] } @@ -26,7 +29,7 @@ func (d *DigitalOcean) NewDroplet(dd *godo.Droplet) *Droplet { droplet.ID = dd.ID droplet.image = dd.Image.Name + " (" + dd.Image.Slug + ")" - if (d.dGrid == nil) { + if d.dGrid == nil { d.dGrid = d.group.NewGrid("grid", 12, 1).Pad() } @@ -56,23 +59,23 @@ func (d *DigitalOcean) NewDroplet(dd *godo.Droplet) *Droplet { droplet.imageN = d.dGrid.NewLabel(dd.Image.Slug) droplet.statusN = d.dGrid.NewLabel(dd.Status) - droplet.connect = d.dGrid.NewButton("Connect", func () { + droplet.connect = d.dGrid.NewButton("Connect", func() { droplet.Connect() }) - droplet.edit = d.dGrid.NewButton("Edit", func () { + droplet.edit = d.dGrid.NewButton("Edit", func() { droplet.Show() }) - droplet.poweroff = d.dGrid.NewButton("Power Off", func () { + droplet.poweroff = d.dGrid.NewButton("Power Off", func() { droplet.PowerOff() }) - droplet.poweron = d.dGrid.NewButton("Power On", func () { + droplet.poweron = d.dGrid.NewButton("Power On", func() { droplet.PowerOn() }) - droplet.destroy = d.dGrid.NewButton("Destroy", func () { + droplet.destroy = d.dGrid.NewButton("Destroy", func() { droplet.Destroy() }) @@ -81,9 +84,11 @@ func (d *DigitalOcean) NewDroplet(dd *godo.Droplet) *Droplet { } func (d *Droplet) Active() bool { - if ! d.Ready() {return false} + if !d.Ready() { + return false + } log.Log(POLL, "droplet.Active() status: ", d.poll.Status, "d.statusN.GetText() =", d.statusN.GetText()) - if (d.statusN.GetText() == "active") { + if d.statusN.GetText() == "active" { return true } return false @@ -91,25 +96,33 @@ func (d *Droplet) Active() bool { // Returns true if the droplet is finished installing func (d *Droplet) Ready() bool { - if d == nil {return false} + if d == nil { + return false + } return d.ready } // Returns true if the droplet is running func (d *Droplet) On() bool { - if ! d.Ready() {return false} + if !d.Ready() { + return false + } return true } func (d *Droplet) HasIPv4() bool { - if ! d.Ready() {return false} + if !d.Ready() { + return false + } if d.ipv4.GetText() == "" { return false } return true } func (d *Droplet) HasIPv6() bool { - if ! d.Ready() {return false} + if !d.Ready() { + return false + } if d.ipv6.GetText() == "" { return false } @@ -117,18 +130,24 @@ func (d *Droplet) HasIPv6() bool { } func (d *Droplet) GetIPv4() string { - if ! d.Ready() {return ""} + if !d.Ready() { + return "" + } return d.ipv4.GetText() } func (d *Droplet) GetIPv6() string { - if ! d.Ready() {return ""} + if !d.Ready() { + return "" + } log.Info("droplet GetIPv6 has: n.GetText()", d.ipv6.GetText()) return d.ipv6.GetText() } func (d *Droplet) Connect() { - if ! d.Ready() {return} + if !d.Ready() { + return + } if d.HasIPv4() { ipv4 := d.GetIPv4() log.Info("droplet has IPv4 =", ipv4) @@ -145,7 +164,9 @@ func (d *Droplet) Connect() { } func (d *Droplet) Update(dpoll *godo.Droplet) { - if ! d.Exists() {return} + if !d.Exists() { + return + } d.poll = dpoll log.Log(POLL, "droplet", dpoll.Name, "dpoll.Status =", dpoll.Status) log.Spew(dpoll) @@ -164,50 +185,58 @@ func (d *Droplet) Update(dpoll *godo.Droplet) { } func (d *Droplet) PowerOn() { - if ! d.Exists() {return} + if !d.Exists() { + return + } log.Info("droplet.PowerOn() should do it here") myDo.PowerOn(d.ID) } func (d *Droplet) PowerOff() { - if ! d.Exists() {return} + if !d.Exists() { + return + } log.Info("droplet.PowerOff() here") myDo.PowerOff(d.ID) } func (d *Droplet) Destroy() { - if ! d.Exists() {return} + if !d.Exists() { + return + } log.Info("droplet.Destroy() ID =", d.ID, "Name =", d.nameN.GetText()) myDo.deleteDroplet(d) } /* -type Droplet struct { - ID int `json:"id,float64,omitempty"` - Name string `json:"name,omitempty"` - Memory int `json:"memory,omitempty"` - Vcpus int `json:"vcpus,omitempty"` - Disk int `json:"disk,omitempty"` - Region *Region `json:"region,omitempty"` - Image *Image `json:"image,omitempty"` - Size *Size `json:"size,omitempty"` - SizeSlug string `json:"size_slug,omitempty"` - BackupIDs []int `json:"backup_ids,omitempty"` - NextBackupWindow *BackupWindow `json:"next_backup_window,omitempty"` - SnapshotIDs []int `json:"snapshot_ids,omitempty"` - Features []string `json:"features,omitempty"` - Locked bool `json:"locked,bool,omitempty"` - Status string `json:"status,omitempty"` - Networks *Networks `json:"networks,omitempty"` - Created string `json:"created_at,omitempty"` - Kernel *Kernel `json:"kernel,omitempty"` - Tags []string `json:"tags,omitempty"` - VolumeIDs []string `json:"volume_ids"` - VPCUUID string `json:"vpc_uuid,omitempty"` -} + type Droplet struct { + ID int `json:"id,float64,omitempty"` + Name string `json:"name,omitempty"` + Memory int `json:"memory,omitempty"` + Vcpus int `json:"vcpus,omitempty"` + Disk int `json:"disk,omitempty"` + Region *Region `json:"region,omitempty"` + Image *Image `json:"image,omitempty"` + Size *Size `json:"size,omitempty"` + SizeSlug string `json:"size_slug,omitempty"` + BackupIDs []int `json:"backup_ids,omitempty"` + NextBackupWindow *BackupWindow `json:"next_backup_window,omitempty"` + SnapshotIDs []int `json:"snapshot_ids,omitempty"` + Features []string `json:"features,omitempty"` + Locked bool `json:"locked,bool,omitempty"` + Status string `json:"status,omitempty"` + Networks *Networks `json:"networks,omitempty"` + Created string `json:"created_at,omitempty"` + Kernel *Kernel `json:"kernel,omitempty"` + Tags []string `json:"tags,omitempty"` + VolumeIDs []string `json:"volume_ids"` + VPCUUID string `json:"vpc_uuid,omitempty"` + } */ func (d *Droplet) Show() { - if ! d.Exists() {return} + if !d.Exists() { + return + } log.Info("droplet: ID =", d.ID) log.Info("droplet: Name =", d.GetName()) log.Info("droplet: Size =", d.GetSize()) @@ -220,47 +249,67 @@ func (d *Droplet) Show() { } func (d *Droplet) Hide() { - if ! d.Exists() {return} + if !d.Exists() { + return + } log.Info("droplet.Hide() window") - if ! d.hidden { + if !d.hidden { // d.window.Hide() } d.hidden = true } func (d *Droplet) Exists() bool { - if ! myDo.Ready() {return false} - if d == nil {return false} - if d.poll == nil {return false} + if !myDo.Ready() { + return false + } + if d == nil { + return false + } + if d.poll == nil { + return false + } return d.ready } func (d *Droplet) GetName() string { - if ! d.Ready() {return ""} + if !d.Ready() { + return "" + } return d.nameN.GetText() } func (d *Droplet) GetSize() string { - if ! d.Ready() {return ""} + if !d.Ready() { + return "" + } return d.sizeSlugN.GetText() } func (d *Droplet) GetMemory() string { - if ! d.Ready() {return ""} + if !d.Ready() { + return "" + } return strconv.Itoa(d.memory) } func (d *Droplet) GetDisk() string { - if ! d.Ready() {return ""} + if !d.Ready() { + return "" + } return strconv.Itoa(d.disk) } func (d *Droplet) GetImage() string { - if ! d.Ready() {return ""} + if !d.Ready() { + return "" + } return d.imageN.GetText() } func (d *Droplet) GetStatus() string { - if ! d.Ready() {return ""} + if !d.Ready() { + return "" + } return d.statusN.GetText() } diff --git a/go.mod b/go.mod index cd492db..26d3dc3 100644 --- a/go.mod +++ b/go.mod @@ -1,26 +1,24 @@ -module go.wit.com/gui/lib/digitalocean +module go.wit.com/lib/gui/digitalocean go 1.21.4 require ( github.com/digitalocean/godo v1.108.0 - go.wit.com/arg v1.4.4 - go.wit.com/gui/gadgets v0.12.5 - go.wit.com/gui/gui v0.12.10 - go.wit.com/log v0.5.5 + go.wit.com/dev/alexflint/arg v1.4.5 + go.wit.com/gui v0.13.11 + go.wit.com/lib/gadgets v0.13.0 + go.wit.com/log v0.5.6 golang.org/x/oauth2 v0.16.0 ) require ( - github.com/alexflint/go-scalar v1.2.0 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-retryablehttp v0.7.4 // indirect - go.wit.com/dev/alexflint/arg v1.4.5 // indirect go.wit.com/dev/alexflint/scalar v1.2.1 // indirect go.wit.com/dev/davecgh/spew v1.1.4 // indirect - go.wit.com/gui/widget v1.1.3 // indirect + go.wit.com/widget v1.1.6 // indirect golang.org/x/net v0.20.0 // indirect golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect google.golang.org/appengine v1.6.7 // indirect diff --git a/go.sum b/go.sum index 08f0f9e..bb3354c 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -github.com/alexflint/go-scalar v1.2.0 h1:WR7JPKkeNpnYIOfHRa7ivM21aWAdHD0gEWHCx+WQBRw= -github.com/alexflint/go-scalar v1.2.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/digitalocean/godo v1.108.0 h1:fWyMENvtxpCpva1UbKzOFnyAS04N1FNuBWWfPeTGquQ= @@ -25,22 +23,20 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -go.wit.com/arg v1.4.4 h1:nfW8JUsVfyXi5l3BlTq5GGhesLlnyh3ICIm8cpM2U8w= -go.wit.com/arg v1.4.4/go.mod h1:P2JoYIsJ9SSvp45qSnYibQEQPNTuTB8dTkyT9y1btsI= go.wit.com/dev/alexflint/arg v1.4.5 h1:asDx5f9IlfpknKjPBqqb2qndE91Pbo7ZDkWUgddfMhY= go.wit.com/dev/alexflint/arg v1.4.5/go.mod h1:wnWc+c6z8kSdDKYriMf6RpM+FiXmo5RYp/t4FNi0MU0= go.wit.com/dev/alexflint/scalar v1.2.1 h1:loXOcbVnd+8YeJRLey+XXidecBiedMDO00zQ26TvKNs= go.wit.com/dev/alexflint/scalar v1.2.1/go.mod h1:+rYsfxqdI2cwA8kJ7GCMwWbNJvfvWUurOCXLiwdTtSs= go.wit.com/dev/davecgh/spew v1.1.4 h1:C9hj/rjlUpdK+E6aroyLjCbS5MFcyNUOuP1ICLWdNek= go.wit.com/dev/davecgh/spew v1.1.4/go.mod h1:sihvWmnQ/09FWplnEmozt90CCVqBtGuPXM811tgfhFA= -go.wit.com/gui/gadgets v0.12.5 h1:Eg7UbwnvwGgYlNX+sgKQNVcbRMZyYL4ChDmS2p/DHtM= -go.wit.com/gui/gadgets v0.12.5/go.mod h1:OB7MtEZy/VK2HrU3yiEuzY9n4LjZwO0L06NYUAFybJs= -go.wit.com/gui/gui v0.12.10 h1:52wFdTqB/GpsFKYFTUvSbHQWNEXz114lhvTfMVrXpYM= -go.wit.com/gui/gui v0.12.10/go.mod h1:YgbFWxsGqZb45oLGaHim2GukPzPgMLQcVRRI0QkrGS8= -go.wit.com/gui/widget v1.1.3 h1:GvLzGSOF9tfmoh6HNbFdN+NSlBo2qeS/Ba2TnQQ1A1U= -go.wit.com/gui/widget v1.1.3/go.mod h1:A6/FaiFQtAHTjgo7c4FrokXe6bXX1Cowo35b2Lgi31E= -go.wit.com/log v0.5.5 h1:bK3b94uVKgev4jB5wg06FnvCFBEapQICTSH2YW+CWr4= -go.wit.com/log v0.5.5/go.mod h1:BaJBfHFqcJSJLXGQ9RHi3XVhPgsStxSMZRlaRxW4kAo= +go.wit.com/gui v0.13.11 h1:d74Ko/XFZYR25P/AZfCQaVO2CuGh1BSjdUp1wjktdDg= +go.wit.com/gui v0.13.11/go.mod h1:v2VgnOL3dlZ13KclYeedZ1cd20nQdvwjyJTNKvFX3DA= +go.wit.com/lib/gadgets v0.13.0 h1:jtsEnf4DHqAxBxuYsaDlHti73rgaxYf/ffAXNB1PJAk= +go.wit.com/lib/gadgets v0.13.0/go.mod h1:xidaHAL6Nk9+M9FkySVU1AG5i39v7T3PuFphUos6LxE= +go.wit.com/log v0.5.6 h1:rDC3ju95zfEads4f1Zm+QMkqjZ39CsYAT/UmQQs7VP4= +go.wit.com/log v0.5.6/go.mod h1:BaJBfHFqcJSJLXGQ9RHi3XVhPgsStxSMZRlaRxW4kAo= +go.wit.com/widget v1.1.6 h1:av2miF5vlohMfARA/QGPTPfgW/ADup1c+oeAOKgroPY= +go.wit.com/widget v1.1.6/go.mod h1:I8tnD3x3ECbB/CRNnLCdC+uoyk7rK0AEkzK1bQYSqoQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= diff --git a/json.go b/json.go index c0aa1a8..4a34261 100644 --- a/json.go +++ b/json.go @@ -1,6 +1,6 @@ package digitalocean -import ( +import ( "encoding/json" ) diff --git a/listKeys.go b/listKeys.go index 4b7da29..7058309 100644 --- a/listKeys.go +++ b/listKeys.go @@ -2,8 +2,9 @@ package digitalocean import ( "context" - "golang.org/x/oauth2" + "github.com/digitalocean/godo" + "golang.org/x/oauth2" "go.wit.com/log" ) @@ -28,10 +29,10 @@ func (d *DigitalOcean) ListSSHKeyID() error { log.Log(POLL, "found ssh key:", key) } /* - sshKeys := []godo.DropletCreateSSHKey{ - {ID: 22994569}, - {ID: 333}, - } + sshKeys := []godo.DropletCreateSSHKey{ + {ID: 22994569}, + {ID: 333}, + } */ // return fmt.Errorf("SSH Key not found") diff --git a/new.go b/new.go index 2b62d12..7584cd2 100644 --- a/new.go +++ b/new.go @@ -1,9 +1,10 @@ package digitalocean -import ( +import ( "os" + + "go.wit.com/gui" "go.wit.com/log" - "go.wit.com/gui/gui" ) var myDo *DigitalOcean @@ -11,7 +12,9 @@ var myDo *DigitalOcean // This is initializes the main DO object // You can only have one of these func New(p *gui.Node) *DigitalOcean { - if myDo != nil {return myDo} + if myDo != nil { + return myDo + } myDo = new(DigitalOcean) myDo.ready = false myDo.parent = p @@ -34,12 +37,16 @@ func New(p *gui.Node) *DigitalOcean { // Returns true if the status is valid func (d *DigitalOcean) Ready() bool { - if d == nil {return false} + if d == nil { + return false + } return d.ready } func (d *DigitalOcean) Show() { - if ! d.Ready() {return} + if !d.Ready() { + return + } log.Info("digitalocean.Show() window") if d.hidden { d.window.Show() @@ -48,21 +55,25 @@ func (d *DigitalOcean) Show() { } func (d *DigitalOcean) Hide() { - if ! d.Ready() {return} + if !d.Ready() { + return + } log.Info("digitalocean.Hide() window") - if ! d.hidden { + if !d.hidden { d.window.Hide() } d.hidden = true } func (d *DigitalOcean) Update() bool { - if ! d.Ready() {return false} + if !d.Ready() { + return false + } d.ListSSHKeyID() if d.ListDroplets() { for _, droplet := range d.dpolled { // check if the droplet ID already exists - if (d.dropMap[droplet.ID] == nil) { + if d.dropMap[droplet.ID] == nil { d.dropMap[droplet.ID] = d.NewDroplet(&droplet) } else { log.Log(POLL, "droplet.Update()", droplet.ID, droplet.Name, "already exists") diff --git a/pollDroplets.go b/pollDroplets.go index b150978..331e191 100644 --- a/pollDroplets.go +++ b/pollDroplets.go @@ -30,20 +30,20 @@ func (d *DigitalOcean) ListDroplets() bool { // Iterate over droplets and print their details. /* - for _, droplet := range d.polled { - 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 _, droplet := range d.polled { + 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) + for _, network := range droplet.Networks.V6 { + if network.Type == "public" { + fmt.Printf("IPv6: %s\n", network.IPAddress) + } } + fmt.Println("-------------------------") } - fmt.Println("-------------------------") - } */ return true diff --git a/structs.go b/structs.go index fdef242..a0c58ec 100644 --- a/structs.go +++ b/structs.go @@ -1,4 +1,4 @@ -/* +/* The Digital Ocean Struct */ @@ -7,85 +7,85 @@ package digitalocean import ( "github.com/digitalocean/godo" - "go.wit.com/gui/gui" - "go.wit.com/gui/gadgets" + "go.wit.com/gui" + "go.wit.com/lib/gadgets" ) type DigitalOcean struct { - ready bool - hidden bool - err error + ready bool + hidden bool + err error - token string // You're Digital Ocean API key - dpolled []godo.Droplet - sshKeys []godo.Key + token string // You're Digital Ocean API key + dpolled []godo.Droplet + sshKeys []godo.Key - dropMap map[int]*Droplet - create *windowCreate + dropMap map[int]*Droplet + create *windowCreate - parent *gui.Node // should be the root of the 'gui' package binary tree - window *gui.Node // our window for displaying digital ocean droplets - group *gui.Node - grid *gui.Node + parent *gui.Node // should be the root of the 'gui' package binary tree + window *gui.Node // our window for displaying digital ocean droplets + group *gui.Node + grid *gui.Node - dGrid *gui.Node // the grid for the droplets + dGrid *gui.Node // the grid for the droplets // Primary Directives - status *gadgets.OneLiner - summary *gadgets.OneLiner - statusIPv4 *gadgets.OneLiner - statusIPv6 *gadgets.OneLiner + status *gadgets.OneLiner + summary *gadgets.OneLiner + statusIPv4 *gadgets.OneLiner + statusIPv6 *gadgets.OneLiner } type windowCreate struct { - ready bool - hidden bool - err error + ready bool + hidden bool + err error - parent *gui.Node // should be the root of the 'gui' package binary tree - window *gui.Node // our window for displaying digital ocean droplets - group *gui.Node - grid *gui.Node + parent *gui.Node // should be the root of the 'gui' package binary tree + window *gui.Node // our window for displaying digital ocean droplets + group *gui.Node + grid *gui.Node - regionSelected godo.Region - regionSlug string - tag *gadgets.OneLiner - name *gadgets.BasicEntry - region *gadgets.BasicDropdown - size *gadgets.BasicCombobox - memory *gadgets.BasicDropdown - image *gadgets.BasicCombobox + regionSelected godo.Region + regionSlug string + tag *gadgets.OneLiner + name *gadgets.BasicEntry + region *gadgets.BasicDropdown + size *gadgets.BasicCombobox + memory *gadgets.BasicDropdown + image *gadgets.BasicCombobox // nvme *gadgets.BasicCheckbox } type ipButton struct { - ip *gui.Node - c *gui.Node + ip *gui.Node + c *gui.Node } type Droplet struct { - ID int - image string - memory int - disk int + ID int + image string + memory int + disk int - ready bool - hidden bool - err error + ready bool + hidden bool + err error - poll *godo.Droplet // store what the digital ocean API returned + poll *godo.Droplet // store what the digital ocean API returned - nameN *gui.Node - sizeSlugN *gui.Node - statusN *gui.Node - imageN *gui.Node + nameN *gui.Node + sizeSlugN *gui.Node + statusN *gui.Node + imageN *gui.Node - destroy *gui.Node - connect *gui.Node - poweron *gui.Node - poweroff *gui.Node - edit *gui.Node + destroy *gui.Node + connect *gui.Node + poweron *gui.Node + poweroff *gui.Node + edit *gui.Node - ipv4 *gui.Node - ipv6 *gui.Node + ipv4 *gui.Node + ipv6 *gui.Node } diff --git a/xterm.go b/xterm.go index 5c94560..403db56 100644 --- a/xterm.go +++ b/xterm.go @@ -1,7 +1,8 @@ package digitalocean -import ( +import ( "os/exec" + "go.wit.com/log" )