package main import "log" import "os" import "time" import "fmt" import "github.com/gookit/config" 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 main() { parseConfig() // only test the socket code if no GUI if (config.String("nogui") == "true") { retrySocket() onExit() } go gui.DoGUI() go retrySocket() // // NOTE: This needs to be something long like 2 seconds. // Not sure way. Otherwise it will hang GTK // /* log.Println("Sleep for 2 seconds, then try to add new tabs") time.Sleep(1 * 1000 * 1000 * 1000) gui.AddChoosersDemo() */ log.Println("Sleep for 2 seconds, then try to add new tabs") time.Sleep(1 * 1000 * 1000 * 1000) gui.AddNewTab(makeCloudInfoBox()) 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) /* log.Println("Sleep for 1000 seconds, then try to add new tabs") time.Sleep(1000 * 1000 * 1000 * 1000) */ /* // THIS CRASHES FOR SOME REASON log.Println("Sleep for 10 seconds, then try to add new tabs") time.Sleep(10 * 1000 * 1000 * 1000) gui.AddEntriesDemo() */ log.Println("Sleep for 2 seconds, then try to add new tabs") time.Sleep(2 * 1000 * 1000 * 1000) 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) } for { // TODO: figure out how to exit 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) }