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