2024-01-01 15:26:36 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-01-07 18:50:36 -06:00
|
|
|
"os"
|
2024-01-01 15:26:36 -06:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
2024-01-25 02:34:18 -06:00
|
|
|
"go.wit.com/gui"
|
|
|
|
"go.wit.com/lib/debugger"
|
|
|
|
"go.wit.com/lib/gui/digitalocean"
|
2024-01-01 15:26:36 -06:00
|
|
|
)
|
|
|
|
|
2024-02-23 22:07:33 -06:00
|
|
|
var title string = "Droplet Control Panel"
|
2024-01-01 15:26:36 -06:00
|
|
|
var myGui *gui.Node
|
|
|
|
var myDo *digitalocean.DigitalOcean
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// initialize a new GO GUI instance
|
|
|
|
myGui = gui.New().Default()
|
|
|
|
|
2024-01-07 18:50:36 -06:00
|
|
|
if os.Getenv("DIGITALOCEAN_TOKEN") == "" {
|
|
|
|
log.Warn("your DIGITALOCEAN_TOKEN environment variable is not set")
|
|
|
|
}
|
|
|
|
|
2024-01-01 15:26:36 -06:00
|
|
|
// draw the main window
|
|
|
|
cloudApp(myGui)
|
|
|
|
|
|
|
|
log.Sleep(1)
|
|
|
|
myDo = digitalocean.New(myGui)
|
|
|
|
myDo.Update()
|
|
|
|
myDo.Show()
|
|
|
|
|
|
|
|
doUpdate()
|
|
|
|
}
|
|
|
|
|
|
|
|
func cloudApp(n *gui.Node) *gui.Node {
|
|
|
|
win := n.NewWindow(title)
|
|
|
|
|
|
|
|
// make a group label and a grid
|
2024-02-09 03:47:15 -06:00
|
|
|
// group := win.NewGroup("data").Pad()
|
|
|
|
box := win.Box()
|
|
|
|
grid := box.NewGrid("grid", 2, 1).Pad()
|
|
|
|
|
|
|
|
grid.NewButton("Show Droplets", func () {
|
|
|
|
if myDo == nil {
|
|
|
|
myDo = digitalocean.New(myGui)
|
|
|
|
} else {
|
|
|
|
myDo.Toggle()
|
|
|
|
}
|
2024-01-01 15:26:36 -06:00
|
|
|
})
|
|
|
|
grid.NewLabel("initializes the DO golang gui package")
|
|
|
|
|
|
|
|
grid.NewButton("Create", func () {
|
|
|
|
// myDo.Create("jcarr.wit.com")
|
|
|
|
digitalocean.InitCreateWindow()
|
|
|
|
})
|
|
|
|
grid.NewLabel("makes a new droplet")
|
|
|
|
|
2024-02-09 03:47:15 -06:00
|
|
|
box.NewButton("gui debugger", func () {
|
2024-01-27 14:24:58 -06:00
|
|
|
debugger.DebugWindow()
|
2024-01-07 18:50:36 -06:00
|
|
|
})
|
|
|
|
grid.NewLabel("make sure you have $ENV(DIGITALOCEAN_TOKEN} set to your API token")
|
|
|
|
|
2024-01-01 15:26:36 -06:00
|
|
|
return win
|
|
|
|
}
|
|
|
|
|
|
|
|
func doUpdate() {
|
|
|
|
ticker := time.NewTicker(10 * time.Second)
|
|
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ticker.C:
|
|
|
|
myDo.Update()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|