blob: ea6638bb1649f23e90dcc10f25c07f002313d664 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
package main
import (
"os"
"time"
"go.wit.com/log"
"go.wit.com/gui"
"go.wit.com/lib/debugger"
"go.wit.com/lib/gui/digitalocean"
)
var title string = "Cloud App"
var myGui *gui.Node
var myDo *digitalocean.DigitalOcean
func main() {
// initialize a new GO GUI instance
myGui = gui.New().Default()
if os.Getenv("DIGITALOCEAN_TOKEN") == "" {
log.Warn("your DIGITALOCEAN_TOKEN environment variable is not set")
}
// 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
group := win.NewGroup("data").Pad()
grid := group.NewGrid("grid", 2, 1).Pad()
grid.NewButton("New()", func () {
myDo = digitalocean.New(myGui)
})
grid.NewLabel("initializes the DO golang gui package")
grid.NewButton("Show", func () {
myDo.Show()
})
grid.NewLabel("will show the DO window")
grid.NewButton("Hide", func () {
myDo.Hide()
})
grid.NewLabel("will hide the DO window")
grid.NewButton("Update", func () {
myDo.Update()
})
grid.NewLabel("polls DO via the API to find the state of all your droplets")
grid.NewButton("Create", func () {
// myDo.Create("jcarr.wit.com")
digitalocean.InitCreateWindow()
})
grid.NewLabel("makes a new droplet")
grid.NewButton("gui debugger", func () {
debugger.DebugWindow(myGui)
})
grid.NewLabel("make sure you have $ENV(DIGITALOCEAN_TOKEN} set to your API token")
return win
}
func doUpdate() {
ticker := time.NewTicker(10 * time.Second)
defer ticker.Stop()
for {
select {
case <-ticker.C:
myDo.Update()
}
}
}
|