builds. gookit/config isn't used anymore instead use protobuf and marshal to JSON

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-24 19:03:15 -07:00
parent 610f04c85a
commit 10e2e7bc45
1 changed files with 50 additions and 36 deletions

86
main.go
View File

@ -13,7 +13,7 @@ import "github.com/golang/protobuf/jsonpb"
import "git.wit.com/wit/gui" import "git.wit.com/wit/gui"
import pb "git.wit.com/wit/witProtobuf" import pb "git.wit.com/wit/witProtobuf"
import "github.com/gookit/config" // import "github.com/gookit/config"
import "github.com/gobuffalo/packr" import "github.com/gobuffalo/packr"
import "github.com/davecgh/go-spew/spew" import "github.com/davecgh/go-spew/spew"
@ -46,20 +46,27 @@ func onExit(err error) {
log.Println("Sleep for 1 second") log.Println("Sleep for 1 second")
time.Sleep(1 * 1000 * 1000 * 1000) time.Sleep(1 * 1000 * 1000 * 1000)
filename := config.String("configfile") filename := pbC.Filename
if (filename == "") { if (filename == "") {
log.Println("NOT SAVING CONFIG FILE") log.Println("NOT SAVING CONFIG FILE")
} else { } else {
log.Println("SAVING CONFIG FILE AS:", filename) marshaler := &jsonpb.Marshaler{}
stuff, _ := marshaler.MarshalToString(pbC)
log.Println(stuff)
// TODO: Fix this
log.Println("FIXME: NOT SAVING CONFIG FILE AS:", filename)
/*
f, err := os.Create(filename + ".yaml") f, err := os.Create(filename + ".yaml")
if err == nil { if err == nil {
config.DumpTo(f, "yaml") // DumpTo(f, "yaml")
} }
f, err = os.Create(filename) f, err = os.Create(filename)
if err == nil { if err == nil {
config.DumpTo(f, "json") // DumpTo(f, "json")
} }
*/
} }
if (err != nil) { if (err != nil) {
@ -83,22 +90,12 @@ func main() {
// This will parse the command line and config file // This will parse the command line and config file
parseConfig(defaultConfig) parseConfig(defaultConfig)
marshaler := &jsonpb.Marshaler{}
stuff, _ := marshaler.MarshalToString(pbC)
log.Println(stuff)
for key, foo := range pbC.Accounts { for key, foo := range pbC.Accounts {
log.Println("account = ", key, foo) log.Println("account = ", key, foo)
} }
gui.Data.Config = pbC gui.Data.Config = pbC
// onExit(nil) // onExit(nil)
// only test the socket code if no GUI
if (config.String("nogui") == "true") {
log.Println("Need to re-implement this")
onExit(nil)
}
initChannel() initChannel()
go processEvents() go processEvents()
@ -127,8 +124,8 @@ func main() {
gui.Data.HomeDir = user.HomeDir gui.Data.HomeDir = user.HomeDir
// Set output debugging level // Set output debugging level
gui.Data.Debug = config.Bool("debugging") gui.Data.Debug = pbC.Debugging
gui.Data.DebugTable = config.Bool("debugtable") gui.Data.DebugTable = pbC.Debugtable
log.Println("gui.Data.Debug = ", gui.Data.Debug) log.Println("gui.Data.Debug = ", gui.Data.Debug)
log.Println("gui.Data.DebugTable = ", gui.Data.DebugTable) log.Println("gui.Data.DebugTable = ", gui.Data.DebugTable)
@ -172,14 +169,15 @@ func mainButtonClick(b *gui.ButtonMap) {
// gui.Data.AccNick = b.AccNick // gui.Data.AccNick = b.AccNick
} else if (b.Note == "CONFIG") { } else if (b.Note == "CONFIG") {
log.Println("TRY TO LOAD DEFAULT CONFIG") log.Println("TRY TO LOAD DEFAULT CONFIG")
defaultConfig, _ := packrBox.FindString("test.json") defaultConfig, _ := packrBox.FindString("protobuf-config.json")
config.LoadData(defaultConfig)
log.Println("defaultConfig =", defaultConfig) log.Println("defaultConfig =", defaultConfig)
for account, _ := range config.StringMap("accounts") { log.Println("NEED TO UNMARSHAL THIS HERE")
log.Println("gui.State = splash BUT THERE IS AN ACCOUNT = ", account) log.Println("NEED TO UNMARSHAL THIS HERE")
log.Println("gui.State = splash BUT THERE IS AN ACCOUNT = ", account) log.Println("NEED TO UNMARSHAL THIS HERE")
log.Println("SETTING gui.State =", gui.Data.State) var newpb *pb.Config
} err := jsonpb.UnmarshalString(defaultConfig, newpb)
log.Println("ATTEMTED TO UNMARSHAL err =", err)
spew.Dump(newpb)
gui.Data.State = "done" gui.Data.State = "done"
} else if (b.Note == "DEBUG") { } else if (b.Note == "DEBUG") {
log.Println("debug.PrintStack() (SHOULD BE JUST THIS goroutine)") log.Println("debug.PrintStack() (SHOULD BE JUST THIS goroutine)")
@ -301,16 +299,32 @@ func mainButtonClick(b *gui.ButtonMap) {
} }
} }
func getToken() string {
if (gui.Data.Current == nil) {
log.Println("gui.Data.Current == nil")
return ""
}
log.Println("gui.Data.Current.Token = ", gui.Data.Current.Token)
return gui.Data.Current.Token
}
// this watches the GUI primarily to process protobuf's // this watches the GUI primarily to process protobuf's
func watchGUI() { func watchGUI() {
count := 0 count := 0
// This is how you marshal into JSON from a Protobuf // This is how you marshal into JSON from a Protobuf
event := pb.MakeGetEvent() event := pb.MakeGetEvent()
event.Token = config.String("accounts." + gui.Data.AccNick + ".token") if (gui.Data.Current == nil) {
log.Println("gui.Data.Current == nil")
} else {
event.Token = gui.Data.Current.Token
}
// event.Token = config.String("accounts." + gui.Data.AccNick + ".token")
marshaler := &jsonpb.Marshaler{} marshaler := &jsonpb.Marshaler{}
stuff, _ := marshaler.MarshalToString(event) stuff, _ := marshaler.MarshalToString(event)
log.Println(stuff) log.Println(stuff)
// also: // also:
// var j *bytes.Buffer // var j *bytes.Buffer
// marshaler.Marshal(j, event) // marshaler.Marshal(j, event)
@ -330,7 +344,7 @@ func watchGUI() {
log.Println("\tTRIGGERING WEBSOCKET HERE on AccNick =", gui.Data.AccNick) log.Println("\tTRIGGERING WEBSOCKET HERE on AccNick =", gui.Data.AccNick)
event := pb.MakeGetEvent() event := pb.MakeGetEvent()
event.Token = config.String("accounts." + gui.Data.AccNick + ".token") event.Token = getToken()
log.Println("\tTRIGGERING WEBSOCKET HERE with event.Token =", event.Token) log.Println("\tTRIGGERING WEBSOCKET HERE with event.Token =", event.Token)
gorillaSendProtobuf(event) gorillaSendProtobuf(event)
@ -342,9 +356,9 @@ func watchGUI() {
log.Println("\tTRIGGERING LOGIN HERE on AccNick =", gui.Data.AccNick) log.Println("\tTRIGGERING LOGIN HERE on AccNick =", gui.Data.AccNick)
event := pb.MakeLoginEvent() event := pb.MakeLoginEvent()
event.Username = config.String("accounts." + gui.Data.AccNick + ".username") // event.Username = config.String("accounts." + gui.Data.AccNick + ".username")
event.Password = config.String("accounts." + gui.Data.AccNick + ".password") // event.Password = config.String("accounts." + gui.Data.AccNick + ".password")
event.Token = config.String("accounts." + gui.Data.AccNick + ".token") // event.Token = config.String("accounts." + gui.Data.AccNick + ".token")
log.Println("\tTRIGGERING LOGIN HERE with event.Token =", event.Token) log.Println("\tTRIGGERING LOGIN HERE with event.Token =", event.Token)
gorillaSendProtobuf(event) gorillaSendProtobuf(event)
@ -354,11 +368,11 @@ func watchGUI() {
log.Println("\tTRIGGERING CREATE HERE") log.Println("\tTRIGGERING CREATE HERE")
event := pb.MakeAddVmEvent() event := pb.MakeAddVmEvent()
event.Username = config.String("accounts." + gui.Data.AccNick + ".username") // event.Username = config.String("accounts." + gui.Data.AccNick + ".username")
event.Email = config.String("accounts." + gui.Data.AccNick + ".email") // event.Email = config.String("accounts." + gui.Data.AccNick + ".email")
//event.Password = config.String("accounts." + gui.Data.AccNick + ".password") //event.Password = config.String("accounts." + gui.Data.AccNick + ".password")
//
event.Token = config.String("accounts." + gui.Data.AccNick + ".token") // event.Token = config.String("accounts." + gui.Data.AccNick + ".token")
log.Println("\tTRIGGERING LOGIN HERE with event.Token =", event.Token) log.Println("\tTRIGGERING LOGIN HERE with event.Token =", event.Token)
spew.Dump(event) spew.Dump(event)
@ -374,9 +388,9 @@ func watchGUI() {
os.Exit(0) os.Exit(0)
} }
if (gui.Data.State == "splash") { if (gui.Data.State == "splash") {
for account, _ := range config.StringMap("accounts") { for key, _ := range pbC.Accounts {
log.Println("gui.State = splash BUT THERE IS AN ACCOUNT = ", account) log.Println("gui.State = splash BUT THERE IS AN ACCOUNT Nick = ", pbC.Accounts[key].Nick)
log.Println("gui.State = splash BUT THERE IS AN ACCOUNT = ", account) log.Println("gui.State = splash BUT THERE IS AN ACCOUNT Username = ", pbC.Accounts[key].Username)
log.Println("SETTING gui.State = main") log.Println("SETTING gui.State = main")
gui.Data.State = "main"; gui.Data.State = "main";
} }