still code restructuring
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
703cf3668e
commit
9e77555991
43
config.go
43
config.go
|
@ -24,10 +24,6 @@ import pb "git.wit.com/wit/witProtobuf"
|
||||||
|
|
||||||
import "github.com/davecgh/go-spew/spew"
|
import "github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
// always override the debugging flag from the command line
|
|
||||||
var debugging *bool
|
|
||||||
var debugtable *bool
|
|
||||||
|
|
||||||
var config *pb.Config
|
var config *pb.Config
|
||||||
|
|
||||||
// This loads the config file and marshals it into the
|
// This loads the config file and marshals it into the
|
||||||
|
@ -76,6 +72,10 @@ var customUsage = func() {
|
||||||
func parseFlags() {
|
func parseFlags() {
|
||||||
var hostname string
|
var hostname string
|
||||||
|
|
||||||
|
// always override the debugging flag from the command line
|
||||||
|
var debugging *bool
|
||||||
|
var debugtable *bool
|
||||||
|
|
||||||
flag.StringVar (&hostname, "hostname", "localhost", "Your full hostname")
|
flag.StringVar (&hostname, "hostname", "localhost", "Your full hostname")
|
||||||
|
|
||||||
height := flag.Int ("height", 0, "Height of the Window")
|
height := flag.Int ("height", 0, "Height of the Window")
|
||||||
|
@ -114,18 +114,6 @@ func parseFlags() {
|
||||||
config.Debugtable = *debugtable
|
config.Debugtable = *debugtable
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseConfig() {
|
|
||||||
// first load the config file
|
|
||||||
loadConfigFile()
|
|
||||||
|
|
||||||
// override the config file from the command line
|
|
||||||
parseFlags()
|
|
||||||
|
|
||||||
log.Println("config.width", config.Width)
|
|
||||||
log.Println("config.height", config.Height)
|
|
||||||
log.Println("config.debugging", config.Debugging)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert a Protobuf to JSON
|
// Convert a Protobuf to JSON
|
||||||
func PBtoJSON() string {
|
func PBtoJSON() string {
|
||||||
// this makes a sample protobuf
|
// this makes a sample protobuf
|
||||||
|
@ -195,6 +183,27 @@ func loadDefaultConfig() pb.Config {
|
||||||
log.Println("jsonpb.Unmarshal() ERROR =", err)
|
log.Println("jsonpb.Unmarshal() ERROR =", err)
|
||||||
}
|
}
|
||||||
spew.Dump(sets)
|
spew.Dump(sets)
|
||||||
// os.Exit(0)
|
|
||||||
return sets
|
return sets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// This is what you call from main()
|
||||||
|
//
|
||||||
|
func parseConfig() {
|
||||||
|
// first load the config file
|
||||||
|
loadConfigFile()
|
||||||
|
|
||||||
|
// override the config file from the command line
|
||||||
|
parseFlags()
|
||||||
|
|
||||||
|
log.Println("config.width", config.Width)
|
||||||
|
log.Println("config.height", config.Height)
|
||||||
|
log.Println("config.debugging", config.Debugging)
|
||||||
|
|
||||||
|
// check that the config parsing worked
|
||||||
|
for key, foo := range config.Accounts {
|
||||||
|
log.Println("account = ", key, foo)
|
||||||
|
log.Println("Accounts[key] = ", config.Accounts[key])
|
||||||
|
}
|
||||||
|
// os.Exit(0)
|
||||||
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ func addEvent(msg *pb.Event) {
|
||||||
func processEvents() {
|
func processEvents() {
|
||||||
for {
|
for {
|
||||||
currentMessage = <-mychannel
|
currentMessage = <-mychannel
|
||||||
log.Println("processEvents() START on channel recieved a message = ", currentMessage)
|
log.Println("processEvents() RECIEVED msg = ", currentMessage)
|
||||||
if (currentMessage.Type == pb.Event_DEMO) {
|
if (currentMessage.Type == pb.Event_DEMO) {
|
||||||
log.Println("processEvents() do Event DEMO")
|
log.Println("processEvents() do Event DEMO")
|
||||||
} else {
|
} else {
|
||||||
|
|
28
gorilla.go
28
gorilla.go
|
@ -12,6 +12,7 @@ import "github.com/gorilla/websocket"
|
||||||
|
|
||||||
import "github.com/golang/protobuf/proto"
|
import "github.com/golang/protobuf/proto"
|
||||||
import pb "git.wit.com/wit/witProtobuf"
|
import pb "git.wit.com/wit/witProtobuf"
|
||||||
|
// import "git.wit.com/wit/gui"
|
||||||
|
|
||||||
var gorillaConn *websocket.Conn
|
var gorillaConn *websocket.Conn
|
||||||
|
|
||||||
|
@ -41,22 +42,25 @@ func gorillaReadProtobuf(conn *websocket.Conn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func gorillaSendProtobuf(msg *pb.Event) {
|
func gorillaSendProtobuf(msg *pb.Event) {
|
||||||
log.Println("gorillaSendProtobuf() START", time.Now())
|
log.Println("gorillaSendProtobuf() Event_Type =", msg.Type, "Event.Account.Nick =", msg.Account)
|
||||||
log.Println("gorillaSendProtobuf()", msg)
|
|
||||||
if (gorillaConn == nil) {
|
if (gorillaConn == nil) {
|
||||||
log.Println("gorillaSendProtobuf() gorillaConn == nil")
|
log.Println("gorillaSendProtobuf() CAN NOT SEND (socket connection isn't open)")
|
||||||
log.Println("Need to re-open connection here")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
msg := pb.CreateSampleEvent()
|
test, err := proto.Marshal(msg)
|
||||||
msg.Name = "test echo over gorilla websocket"
|
if err != nil {
|
||||||
*/
|
log.Println("gorillaConn.WriteMessage() Marshal failed SERIOUS ERROR", err)
|
||||||
log.Println("gorillaSendProtobuf() going to Marshal msg =", msg)
|
log.Println("gorillaConn.WriteMessage() Marshal failed SERIOUS ERROR", err)
|
||||||
data, _ := proto.Marshal(msg)
|
log.Println("gorillaConn.WriteMessage() Marshal failed SERIOUS ERROR", err)
|
||||||
err2 := gorillaConn.WriteMessage(websocket.BinaryMessage, data)
|
// TODO: return here?
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err2 := gorillaConn.WriteMessage(websocket.BinaryMessage, test)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
log.Println("write:", err2)
|
log.Println("gorillaConn.WriteMessage() failed write:", err2)
|
||||||
gorillaConn = nil
|
gorillaConn = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
57
main.go
57
main.go
|
@ -155,17 +155,18 @@ func main() {
|
||||||
// might be a good approach. Time will tell...
|
// might be a good approach. Time will tell...
|
||||||
//
|
//
|
||||||
func mainMouseClick(b *gui.ButtonMap) {
|
func mainMouseClick(b *gui.ButtonMap) {
|
||||||
log.Println("mainMouseClick() b =", b)
|
|
||||||
|
|
||||||
if (b == nil) {
|
if (b == nil) {
|
||||||
log.Println("main() BACK IN CONTROL PANEL CODE (button is nil) WHY DID THIS HAPPEN?")
|
log.Println("main() BACK IN CONTROL PANEL CODE (button is nil) WHY DID THIS HAPPEN?")
|
||||||
log.Println("main() BACK IN CONTROL PANEL CODE (button is nil) WHY DID THIS HAPPEN?")
|
log.Println("main() BACK IN CONTROL PANEL CODE (button is nil) WHY DID THIS HAPPEN?")
|
||||||
onExit(fmt.Errorf("mainMouseClick() got b = nil"))
|
onExit(fmt.Errorf("mainMouseClick() got b = nil"))
|
||||||
}
|
}
|
||||||
|
log.Println("mainMouseClick() b.Action =", b.Action)
|
||||||
|
|
||||||
gui.Data.Current = b.Account
|
gui.Data.Current = b.Account
|
||||||
log.Println("main() BACK IN CONTROL PANEL CODE (button =", b, ")")
|
log.Println("main() BACK IN CONTROL PANEL CODE")
|
||||||
log.Println("\tmainMouseClick() setting current account = ", b.Account)
|
if (b.Account != nil) {
|
||||||
|
log.Println("\tmainMouseClick() setting current account = ", b.Account.Nick)
|
||||||
|
}
|
||||||
if (b.Action == "BACK") {
|
if (b.Action == "BACK") {
|
||||||
gui.Data.State = "splash"
|
gui.Data.State = "splash"
|
||||||
} else if (b.Action == "QUIT") {
|
} else if (b.Action == "QUIT") {
|
||||||
|
@ -214,10 +215,10 @@ func mainMouseClick(b *gui.ButtonMap) {
|
||||||
event.Account = b.Account
|
event.Account = b.Account
|
||||||
prepareAndSend(event)
|
prepareAndSend(event)
|
||||||
|
|
||||||
count := 0
|
// count := 0
|
||||||
for {
|
for {
|
||||||
log.Println("\tSleep() in buttonClick() gui.Data.State =", gui.Data.State)
|
log.Println("\tSleep() in buttonClick() gui.Data.State =", gui.Data.State)
|
||||||
time.Sleep(200 * time.Millisecond)
|
time.Sleep(20 * time.Millisecond)
|
||||||
if (gui.Data.State == "NEW PROTOBUF") {
|
if (gui.Data.State == "NEW PROTOBUF") {
|
||||||
if (currentMessage == nil) {
|
if (currentMessage == nil) {
|
||||||
gui.SocketError()
|
gui.SocketError()
|
||||||
|
@ -225,13 +226,13 @@ func mainMouseClick(b *gui.ButtonMap) {
|
||||||
} else {
|
} else {
|
||||||
log.Println("LOGIN currentMessage =", currentMessage)
|
log.Println("LOGIN currentMessage =", currentMessage)
|
||||||
if (currentMessage.Type == pb.Event_OK) {
|
if (currentMessage.Type == pb.Event_OK) {
|
||||||
log.Println("\tLOGIN WAS OK!")
|
|
||||||
log.Println("\tLOGIN WAS OK!")
|
|
||||||
log.Println("\tLOGIN WAS OK!")
|
|
||||||
msg := "On account " + b.Account.Nick + "\n"
|
msg := "On account " + b.Account.Nick + "\n"
|
||||||
|
log.Println("\tLOGIN WAS OK!", msg)
|
||||||
|
log.Println("\tLOGIN WAS OK! old button.Account was =", b.Account)
|
||||||
|
log.Println("\tLOGIN WAS OK! currentMessage.Account =", currentMessage.Account)
|
||||||
|
log.Println("\tLOGIN WAS OK!")
|
||||||
gui.MessageWindow("Login OK", msg)
|
gui.MessageWindow("Login OK", msg)
|
||||||
}
|
} else if (currentMessage.Type == pb.Event_FAIL) {
|
||||||
if (currentMessage.Type == pb.Event_FAIL) {
|
|
||||||
log.Println("\tLOGIN FAILED")
|
log.Println("\tLOGIN FAILED")
|
||||||
log.Println("\tLOGIN FAILED")
|
log.Println("\tLOGIN FAILED")
|
||||||
log.Println("\tLOGIN FAILED")
|
log.Println("\tLOGIN FAILED")
|
||||||
|
@ -247,6 +248,8 @@ func mainMouseClick(b *gui.ButtonMap) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
TODO: fix this with an actual timeout
|
||||||
count += 1
|
count += 1
|
||||||
if (count > 10) {
|
if (count > 10) {
|
||||||
log.Println("\tERROR: waited too long for a resposne")
|
log.Println("\tERROR: waited too long for a resposne")
|
||||||
|
@ -254,6 +257,7 @@ func mainMouseClick(b *gui.ButtonMap) {
|
||||||
gui.Data.State = "done"
|
gui.Data.State = "done"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
} else if (b.Action == "SHOW") {
|
} else if (b.Action == "SHOW") {
|
||||||
log.Println("\tTRIGGER DISPLAY ACCOUNT")
|
log.Println("\tTRIGGER DISPLAY ACCOUNT")
|
||||||
|
@ -306,20 +310,13 @@ func mainMouseClick(b *gui.ButtonMap) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareAndSend(event *pb.Event) {
|
func prepareAndSend(event *pb.Event) {
|
||||||
/*
|
|
||||||
// This is sent in the Account now
|
|
||||||
if (gui.Data.Current != nil) {
|
|
||||||
event.Token = gui.Data.Current.Token
|
|
||||||
event.Username = gui.Data.Current.Username
|
|
||||||
event.Password = gui.Data.Current.Password
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (event.Account == nil) {
|
if (event.Account == nil) {
|
||||||
log.Println("\tmain.prepareAndSend() ERROR event.Token = nil")
|
log.Println("\tmain.prepareAndSend() ERROR event.Token = nil")
|
||||||
log.Println("\tmain.prepareAndSend() ERROR event.Token = nil")
|
log.Println("\tmain.prepareAndSend() ERROR event.Token = nil")
|
||||||
log.Println("\tmain.prepareAndSend() ERROR event.Token = nil")
|
log.Println("\tmain.prepareAndSend() ERROR event.Token = nil")
|
||||||
} else {
|
} else {
|
||||||
log.Println("\tmain.prepareAndSend() event.Token =", event.Account.Token)
|
s := event.Account.Token
|
||||||
|
log.Println("\tmain.prepareAndSend() event.Token(-24:) =", s[len(s)-24:])
|
||||||
}
|
}
|
||||||
gorillaSendProtobuf(event)
|
gorillaSendProtobuf(event)
|
||||||
gui.Data.State = "READ PROTOBUF"
|
gui.Data.State = "READ PROTOBUF"
|
||||||
|
@ -342,13 +339,6 @@ func watchGUI() {
|
||||||
event := pb.MakeGetEvent()
|
event := pb.MakeGetEvent()
|
||||||
prepareAndSend(event)
|
prepareAndSend(event)
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if (gui.Data.State == "SEND LOGIN") {
|
|
||||||
log.Println("\tTRIGGERING LOGIN")
|
|
||||||
event := pb.MakeLoginEvent()
|
|
||||||
prepareAndSend(event)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (gui.Data.State == "CREATE") {
|
if (gui.Data.State == "CREATE") {
|
||||||
log.Println("\tTRIGGERING CREATE")
|
log.Println("\tTRIGGERING CREATE")
|
||||||
event := pb.MakeAddVmEvent()
|
event := pb.MakeAddVmEvent()
|
||||||
|
@ -361,11 +351,20 @@ func watchGUI() {
|
||||||
onExit(nil)
|
onExit(nil)
|
||||||
}
|
}
|
||||||
if (gui.Data.State == "splash") {
|
if (gui.Data.State == "splash") {
|
||||||
|
if (config == nil) {
|
||||||
|
log.Println("gui.State = splash BUT SOMETHING HAS GONE VERY WRONG")
|
||||||
|
log.Println("gui.State = splash BUT SOMETHING HAS GONE VERY WRONG")
|
||||||
|
log.Println("gui.State = splash config = nil")
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
for key, _ := range config.Accounts {
|
for key, _ := range config.Accounts {
|
||||||
log.Println("gui.State = splash BUT THERE IS AN ACCOUNT Nick = ", config.Accounts[key].Nick)
|
log.Println("gui.State = splash BUT THERE IS AN ACCOUNT Account = ", config.Accounts[key])
|
||||||
log.Println("gui.State = splash BUT THERE IS AN ACCOUNT Username = ", config.Accounts[key].Username)
|
// log.Println("gui.State = splash BUT THERE IS AN ACCOUNT Username = ", config.Accounts[key])
|
||||||
log.Println("SETTING gui.State = main")
|
log.Println("SETTING gui.State = main")
|
||||||
gui.Data.State = "main";
|
gui.Data.State = "main";
|
||||||
|
if (config.Accounts[key] == nil) {
|
||||||
|
log.Println("THIS IS LAME. CONFIG FILE MADE NULL ACCOUNTS key =", key)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,22 +6,28 @@
|
||||||
"nick": "jcarr",
|
"nick": "jcarr",
|
||||||
"username": "jcarr@wit.com",
|
"username": "jcarr@wit.com",
|
||||||
"token": "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJ4IjozLCJyIjoiIiwiY3NyZiI6InRBY1p2eXVJbk1YdWUxV0RSbDFIeDI5YSIsImV4cCI6MTU1OTI3MDQwMCwiaXNzIjoid2l0Iiwic3ViIjoiamNhcnJAd2l0LmNvbSJ9.bqXX_6yrUHQGYh3SEmW8ydSa9Xfqx-HIKutTN_GirwhC_VrVX1xJBcgYfjdKGegvwY7Td1vO3rs40Iz7ifcptrtdzJnDX62d_1JJPKBHUQUfnTLr2qoTgaljElFM0Q_e",
|
"token": "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJ4IjozLCJyIjoiIiwiY3NyZiI6InRBY1p2eXVJbk1YdWUxV0RSbDFIeDI5YSIsImV4cCI6MTU1OTI3MDQwMCwiaXNzIjoid2l0Iiwic3ViIjoiamNhcnJAd2l0LmNvbSJ9.bqXX_6yrUHQGYh3SEmW8ydSa9Xfqx-HIKutTN_GirwhC_VrVX1xJBcgYfjdKGegvwY7Td1vO3rs40Iz7ifcptrtdzJnDX62d_1JJPKBHUQUfnTLr2qoTgaljElFM0Q_e",
|
||||||
"hostname": "hosttest.wit.com",
|
"hostname": "customers.wprod.wit.com",
|
||||||
"domainname": "test.wit.com"
|
"password": "yowzayowza",
|
||||||
|
"URL": "http://stackapi:4000/",
|
||||||
|
"domain": "test.wit.com"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"nick": "jcarr2",
|
"nick": "jcarr2",
|
||||||
"username": "jcarr@wit.com",
|
"username": "jcarr@wit.com",
|
||||||
|
"email": "jcarr@wit.com",
|
||||||
|
"password": "yowzayowza",
|
||||||
|
"URL": "http://stackapi:4000/",
|
||||||
|
"hostname": "customers.wprod.wit.com",
|
||||||
"token": "brokenToken",
|
"token": "brokenToken",
|
||||||
"hostname": "hosttest.wit.com",
|
"domain": "test.wit.com"
|
||||||
"domainname": "test.wit.com"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"nick": "bmath",
|
"nick": "bmath",
|
||||||
"username": "bmath@wit.com",
|
"username": "bmath@wit.com",
|
||||||
"token": "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJ4IjoyLCJyIjoiIiwiY3NyZiI6ImJRSVFtV2JjdktUN2FtUWpEZWlMUFhXeSIsImV4cCI6MTU1OTQzMTgzNiwiaXNzIjoid2l0Iiwic3ViIjoiYm1hdGhAd2l0LmNvbSJ9.9hdVWBZwAA1Hssf6Oh9UlP_DW3TPIv30wuq8pyhQHtQLaBgAXgaSqwBbGOWrjhYixQlzfUCZ6Oym6AqVNJ3H5_lPl3wwUm7Qz3G0zmenV2BE54rtVoENbzm_cKSzMqco",
|
"token": "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJ4IjoyLCJyIjoiIiwiY3NyZiI6ImJRSVFtV2JjdktUN2FtUWpEZWlMUFhXeSIsImV4cCI6MTU1OTQzMTgzNiwiaXNzIjoid2l0Iiwic3ViIjoiYm1hdGhAd2l0LmNvbSJ9.9hdVWBZwAA1Hssf6Oh9UlP_DW3TPIv30wuq8pyhQHtQLaBgAXgaSqwBbGOWrjhYixQlzfUCZ6Oym6AqVNJ3H5_lPl3wwUm7Qz3G0zmenV2BE54rtVoENbzm_cKSzMqco",
|
||||||
"hostname": "customers.wprod.wit.com",
|
"hostname": "customers.wprod.wit.com",
|
||||||
"domainname": "testing.com"
|
"URL": "http://stackapi:4000/",
|
||||||
|
"domain": "testing.com"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
{
|
|
||||||
"USER": "jcarr",
|
|
||||||
"width": 700,
|
|
||||||
"height": 600,
|
|
||||||
"filename": "/home/jcarr/.config/cloud-control-panel.json",
|
|
||||||
"accounts": [
|
|
||||||
{
|
|
||||||
"nick": "jcarr",
|
|
||||||
"username": "jcarr@wit.com",
|
|
||||||
"token": "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJ4IjozLCJyIjoiIiwiY3NyZiI6InRBY1p2eXVJbk1YdWUxV0RSbDFIeDI5YSIsImV4cCI6MTU1OTI3MDQwMCwiaXNzIjoid2l0Iiwic3ViIjoiamNhcnJAd2l0LmNvbSJ9.bqXX_6yrUHQGYh3SEmW8ydSa9Xfqx-HIKutTN_GirwhC_VrVX1xJBcgYfjdKGegvwY7Td1vO3rs40Iz7ifcptrtdzJnDX62d_1JJPKBHUQUfnTLr2qoTgaljElFM0Q_e",
|
|
||||||
"hostname": "hosttest.wit.com",
|
|
||||||
"domainname": "test.wit.com"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"nick": "jcarr2",
|
|
||||||
"username": "jcarr@wit.com",
|
|
||||||
"token": "brokenToken",
|
|
||||||
"hostname": "hosttest.wit.com",
|
|
||||||
"domainname": "test.wit.com"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"nick": "bmath",
|
|
||||||
"username": "bmath@wit.com",
|
|
||||||
"token": "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJ4IjoyLCJyIjoiIiwiY3NyZiI6Ik9rR0JWenphV2cxQjVlN0R5YjRXSzIyWCIsImV4cCI6MTU1OTE4NTc1MiwiaXNzIjoid2l0Iiwic3ViIjoiYm1hdGhAd2l0LmNvbSJ9.vdOAXyt3VIovqEIbivgt6upqR8glZv2UdzFcyudzCmGV-msdZWi_9TZaATyQMxEaVD3K6gRunakyOWK0jw4xxeDUbQym86IKMU2UOjp0tN0z72OmH822NmQ8_AgWiKNI",
|
|
||||||
"hostname": "hosttest.wit.com",
|
|
||||||
"domainname": "test.wit.com"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
{}
|
|
Loading…
Reference in New Issue