cloud-control-panel/main.go

97 lines
2.2 KiB
Go
Raw Normal View History

package main
import "log"
import "os"
import "time"
import "fmt"
import "github.com/gookit/config"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
import "git.wit.com/wit/gui"
// import "github.com/davecgh/go-spew/spew"
// reminder to use this for JSON
// https://github.com/tidwall/gjson
// value := gjson.Get(json, "name.last")
// println(value.String())
// value := gjson.Get(json, friends.#[last=="Murphy"].first)
// use mergo to merge structs
// import "github.com/imdario/mergo"
// mergo.Merge(&dest, src)
// always sorted slice (new project)
// https://github.com/yaa110/sslice
func add2() {
var parts []gui.InputData
for key, foo := range []string{"BG", "TEXTCOLOR", "BUTTON", "TEXTCOLOR", "TEXTCOLOR", "TEXT", "BUTTON", "TEXT", "BUTTON"} {
log.Println(key, foo)
var b gui.InputData
b.CellType = foo
b.Heading = fmt.Sprintf("heading%d", key)
parts = append(parts, b)
}
log.Println("Sleep for 2 seconds, then try to add new tabs")
time.Sleep(1 * 1000 * 1000 * 1000)
gui.AddTableTab("test seven", 7, parts)
}
func main() {
parseConfig()
// only test the socket code if no GUI
if (config.String("nogui") == "true") {
retrySocket()
onExit()
}
go retrySocket()
// make this the main loop in an attempt to figure out the crashes
// do not change this until the GUI is stable
ui.Main(setupCloudUI)
/*
for account, _ := range config.StringMap("cloud") {
port := config.String("cloud." + account + ".port")
proto := config.String("cloud." + account + ".proto")
hostname := config.String("cloud." + account + ".hostname")
rows := config.Int("cloud." + account + ".rows")
fmt.Println(hostname, port, proto, rows)
gui.AddTableTab(account, rows, parts)
log.Println("Sleep for 10 seconds, then add next table")
time.Sleep(10 * 1000 * 1000 * 1000)
}
*/
}
// Exit and write out the config
// (in yaml and json I guess.)
// switch to json once it can be made human readable
func onExit() {
log.Println("Sleep for 1 second")
time.Sleep(1 * 1000 * 1000 * 1000)
f, err := os.Create("/tmp/cloud-control-panel.yaml")
if err == nil {
config.DumpTo(f, "yaml")
}
f, err = os.Create("/tmp/cloud-control-panel.json")
if err == nil {
config.DumpTo(f, "json")
}
os.Exit(0)
}