73 lines
2.0 KiB
Go
73 lines
2.0 KiB
Go
package main
|
|
|
|
/*
|
|
This simply parses the command line arguments using the default golang
|
|
package called 'flag'. This can be used as a simple template to parse
|
|
command line arguments in other programs.
|
|
|
|
It puts everything in the 'config' package which I think is a good
|
|
wrapper around the 'flags' package and doesn't need a whole mess of
|
|
global variables
|
|
*/
|
|
|
|
import "log"
|
|
import "strings"
|
|
import "io/ioutil"
|
|
|
|
import "github.com/golang/protobuf/jsonpb"
|
|
import pb "git.wit.com/wit/witProtobuf"
|
|
|
|
import "github.com/davecgh/go-spew/spew"
|
|
|
|
// will load the default config from within the go binary
|
|
func loadDefaultConfig(a string) pb.Config {
|
|
log.Println("TRY TO LOAD DEFAULT CONFIG")
|
|
log.Println("a =", a)
|
|
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
|
|
// var newpb *pb.Config
|
|
sets := pb.Config{}
|
|
|
|
b, err := ioutil.ReadFile("../resources/protobuf-config.json")
|
|
if err != nil {
|
|
log.Println("ioutil.ReadFile() ERROR =", err)
|
|
}
|
|
log.Println("ioutil.ReadFile() b =", b)
|
|
|
|
err = jsonpb.Unmarshal(strings.NewReader(string(b)), &sets)
|
|
if err != nil {
|
|
log.Println("jsonpb.Unmarshal() ERROR =", err)
|
|
}
|
|
spew.Dump(sets)
|
|
return sets
|
|
//
|
|
// err := jsonpb.UnmarshalString(defaultConfig, newpb)
|
|
log.Println("ATTEMTED TO UNMARSHAL err =", err)
|
|
spew.Dump(newpb)
|
|
if (err == nil) {
|
|
log.Println("SETTING config to the default config", err)
|
|
// TODO: save the protobuf somewhere as the user could loose the tokens
|
|
log.Println("THIS IS PROBABLY REALLY BAD", err)
|
|
log.Println("THIS IS PROBABLY REALLY BAD", err)
|
|
log.Println("THIS IS PROBABLY REALLY BAD", err)
|
|
// config = newpb
|
|
}
|
|
return sets
|
|
}
|
|
|
|
func unmarshalConfig(a string) *pb.Event {
|
|
var newpb *pb.Event
|
|
log.Println("ATTEMTED TO UNMARSHAL string =", a)
|
|
err := jsonpb.UnmarshalString(a, newpb)
|
|
log.Println("ATTEMTED TO UNMARSHAL err =", err)
|
|
spew.Dump(newpb)
|
|
return newpb
|
|
}
|
|
|
|
func main() {
|
|
blah := "{}"
|
|
loadDefaultConfig(blah)
|
|
}
|