sends the token

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-23 19:36:20 -07:00
parent 833deb095c
commit 8b041a97d7
5 changed files with 36 additions and 29 deletions

View File

@ -33,7 +33,7 @@ var customUsage = func() {
fmt.Println("") fmt.Println("")
fmt.Println("EXAMPLES:") fmt.Println("EXAMPLES:")
fmt.Println("") fmt.Println("")
fmt.Println(os.Args[0] + "--hostname test.hostname.wit.com") fmt.Println(os.Args[0] + " --hostname test.hostname.wit.com")
fmt.Println("") fmt.Println("")
} }
@ -128,31 +128,14 @@ func parseConfig(defaultConfig string) {
// always override the debugging flag from the command line // always override the debugging flag from the command line
config.Set("debugging", *debugging) config.Set("debugging", *debugging)
for _, addr := range config.Strings("arr1") {
log.Println("addr =", addr)
}
map1 := config.StringMap("map1")
fmt.Printf("%#v\n",map1)
log.Println(config.String("map1.key1.jwc1"))
for account, _ := range config.StringMap("cloud") { for account, _ := range config.StringMap("cloud") {
port := config.String("accounts." + account + ".port") port := config.String("accounts." + account + ".port")
proto := config.String("accounts." + account + ".proto") proto := config.String("accounts." + account + ".proto")
hostname := config.String("accounts." + account + ".hostname") hostname := config.String("accounts." + account + ".hostname")
fmt.Println(account, hostname, port, proto) log.Println(account, hostname, port, proto)
} }
if (config.String("nogui") == "true") { if (config.String("nogui") == "true") {
log.Println("DO NOT DISPLAY THE GUI") log.Println("DO NOT DISPLAY THE GUI")
} }
if (config.String("debugging") == "true") {
log.Println("ENABLE DEBUG", config.String("debugging"))
log.Println("ENABLE DEBUG", config.Bool("debugging"))
} else {
log.Println("DISABLE DEBUG", config.String("debugging"))
log.Println("DISABLE DEBUG", config.Bool("debugging"))
}
} }

View File

@ -58,6 +58,7 @@ func processEvents() {
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 {
log.Println("processEvents() NEW PROTOBUF")
gui.Data.State = "NEW PROTOBUF" gui.Data.State = "NEW PROTOBUF"
} }
log.Println("processEvents() END on channel") log.Println("processEvents() END on channel")

View File

@ -15,9 +15,9 @@ import pb "git.wit.com/wit/witProtobuf"
var gorillaConn *websocket.Conn var gorillaConn *websocket.Conn
func readGorillaConn(conn *websocket.Conn) { func gorillaReadProtobuf(conn *websocket.Conn) {
for { for {
log.Println("gorilla START readGorillaConn()", time.Now()) log.Println("gorilla START gorillaReadProtobuf()", time.Now())
mytype, message, err := conn.ReadMessage() mytype, message, err := conn.ReadMessage()
if err != nil { if err != nil {
log.Println("read:", err) log.Println("read:", err)
@ -29,25 +29,28 @@ func readGorillaConn(conn *websocket.Conn) {
if (err != nil) { if (err != nil) {
log.Printf("readConn() something fucked up happened in Unmarshal") log.Printf("readConn() something fucked up happened in Unmarshal")
} }
log.Printf("readGorillaConn() successfully read protobuf from gorilla websocket") log.Printf("gorillaReadProtobuf() successfully read protobuf from gorilla websocket")
addEvent(protobufMsg) addEvent(protobufMsg)
} else { } else {
log.Printf("recv: %s", message) log.Printf("recv: %s", message)
// log.Printf("type, err = ", mytype, err) // log.Printf("type, err = ", mytype, err)
} }
time.Sleep(time.Second) time.Sleep(time.Second)
log.Println("gorilla END readGorillaConn()", time.Now()) log.Println("gorilla END gorillaReadProtobuf()", time.Now())
} }
} }
func gorillaSendProtobuf() { func gorillaSendProtobuf(msg *pb.Event) {
log.Println("gorillaSendProtobuf() START", time.Now())
if (gorillaConn == nil) { if (gorillaConn == nil) {
log.Println("gorillaSendProtobuf() gorillaConn == nil") log.Println("gorillaSendProtobuf() gorillaConn == nil")
log.Println("Need to re-open connection here") log.Println("Need to re-open connection here")
return return
} }
/*
msg := pb.CreateSampleEvent() msg := pb.CreateSampleEvent()
msg.Name = "test echo over gorilla websocket" msg.Name = "test echo over gorilla websocket"
*/
data, _ := proto.Marshal(msg) data, _ := proto.Marshal(msg)
err2 := gorillaConn.WriteMessage(websocket.BinaryMessage, data) err2 := gorillaConn.WriteMessage(websocket.BinaryMessage, data)
if err2 != nil { if err2 != nil {
@ -93,7 +96,7 @@ func gorillaDial(hostname string) {
gorillaConn = conn gorillaConn = conn
// handle inbound messages on the channel // handle inbound messages on the channel
readGorillaConn(conn) gorillaReadProtobuf(conn)
closeGorillaConn() closeGorillaConn()
} }

26
main.go
View File

@ -10,6 +10,9 @@ import "runtime/debug"
import "github.com/gookit/config" import "github.com/gookit/config"
import "github.com/gobuffalo/packr" import "github.com/gobuffalo/packr"
// import "github.com/golang/protobuf/proto"
import pb "git.wit.com/wit/witProtobuf"
import "git.wit.com/wit/gui" import "git.wit.com/wit/gui"
var GITCOMMIT string // this is passed in as an ldflag var GITCOMMIT string // this is passed in as an ldflag
@ -155,8 +158,9 @@ func buttonClick(b *gui.ButtonMap) {
} }
if (b.Note == "SHOW") { if (b.Note == "SHOW") {
log.Println("\tTRIGGER DISPLAY ACCOUNT") log.Println("\tTRIGGER DISPLAY ACCOUNT")
gui.Data.State = "READ WEBSOCKET" gui.Data.State = "SEND WEBSOCKET"
gui.Data.AccNick = b.AccNick gui.Data.AccNick = b.AccNick
count := 0
for { for {
log.Println("Sleep() in buttonClick() gui.Data.State =", gui.Data.State) log.Println("Sleep() in buttonClick() gui.Data.State =", gui.Data.State)
time.Sleep(200 * time.Millisecond) time.Sleep(200 * time.Millisecond)
@ -178,6 +182,13 @@ func buttonClick(b *gui.ButtonMap) {
} }
return return
} }
count += 1
if (count > 10) {
log.Println("ERROR: waited too long for a resposne")
currentMessage = nil
gui.Data.State = "done"
return
}
} }
} }
if (b.Note == "BMATH") { if (b.Note == "BMATH") {
@ -229,14 +240,21 @@ func watchGUI() {
log.Println("\tTRIGGERING BMATH HERE") log.Println("\tTRIGGERING BMATH HERE")
log.Println("\tTRIGGERING BMATH HERE") log.Println("\tTRIGGERING BMATH HERE")
log.Println("\tTRIGGERING BMATH HERE") log.Println("\tTRIGGERING BMATH HERE")
gorillaSendProtobuf() event := pb.MakeGetEvent()
gorillaSendProtobuf(event)
} }
if (gui.Data.State == "READ WEBSOCKET") { if (gui.Data.State == "SEND WEBSOCKET") {
log.Println("\tTRIGGERING WEBSOCKET HERE on AccNick =", gui.Data.AccNick) log.Println("\tTRIGGERING WEBSOCKET HERE on AccNick =", gui.Data.AccNick)
log.Println("\tTRIGGERING WEBSOCKET HERE on AccNick =", gui.Data.AccNick) log.Println("\tTRIGGERING WEBSOCKET HERE on AccNick =", gui.Data.AccNick)
log.Println("\tTRIGGERING WEBSOCKET HERE on AccNick =", gui.Data.AccNick) log.Println("\tTRIGGERING WEBSOCKET HERE on AccNick =", gui.Data.AccNick)
event := pb.MakeGetEvent()
event.Token = config.String("accounts." + gui.Data.AccNick + ".token")
log.Println("\tTRIGGERING WEBSOCKET HERE with event.Token =", event.Token)
if (gui.Data.AccNick == "bmath") { if (gui.Data.AccNick == "bmath") {
gorillaSendProtobuf() gorillaSendProtobuf(event)
gui.Data.State = "READ PROTOBUF"
} else { } else {
gui.Data.State = "NEW PROTOBUF" gui.Data.State = "NEW PROTOBUF"
} }

View File

@ -8,6 +8,7 @@
"hostname": "v000185.testing.com.customers.wprod.wit.com", "hostname": "v000185.testing.com.customers.wprod.wit.com",
"username": "bmath@wit.com", "username": "bmath@wit.com",
"port": 9000, "port": 9000,
"token": "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJ4IjoyLCJyIjoiIiwiY3NyZiI6Ik9rR0JWenphV2cxQjVlN0R5YjRXSzIyWCIsImV4cCI6MTU1OTE4NTc1MiwiaXNzIjoid2l0Iiwic3ViIjoiYm1hdGhAd2l0LmNvbSJ9.vdOAXyt3VIovqEIbivgt6upqR8glZv2UdzFcyudzCmGV-msdZWi_9TZaATyQMxEaVD3K6gRunakyOWK0jw4xxeDUbQym86IKMU2UOjp0tN0z72OmH822NmQ8_AgWiKNI",
"proto": "tcp" "proto": "tcp"
}, },
"jcarr": { "jcarr": {
@ -16,6 +17,7 @@
"username": "jcarr@wit.com", "username": "jcarr@wit.com",
"port": 3333, "port": 3333,
"proto": "tcp", "proto": "tcp",
"token": "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJ4IjoyLCJyIjoiIiwiY3NyZiI6Ik9rR0JWenphV2cxQjVlN0R5YjRXSzIyWCIsImV4cCI6MTU1OTE4NTc1MiwiaXNzIjoid2l0Iiwic3ViIjoiYm1hdGhAd2l0LmNvbSJ9.vdOAXyt3VIovqEIbivgt6upqR8glZv2UdzFcyudzCmGV-msdZWi_9TZaATyQMxEaVD3K6gRunakyOWK0jw4xxeDUbQym86IKMU2UOjp0tN0z72OmH822NmQ8_AgWiKNI",
"rows": 18 "rows": 18
}, },
"jcarr2": { "jcarr2": {