45 lines
1.1 KiB
Go
45 lines
1.1 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.org/jcarr/witProtobuf"
|
||
|
|
||
|
import "github.com/davecgh/go-spew/spew"
|
||
|
|
||
|
// TEST UNMARSHAL JSON TO PROTOBUF
|
||
|
// This is known to crash unless done exactly like this
|
||
|
// with strings.NewReader & 'sets'
|
||
|
func loadDefaultConfig(a string) pb.Config {
|
||
|
sets := pb.Config{}
|
||
|
|
||
|
b, err := ioutil.ReadFile("cloud-control-panel.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
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
loadDefaultConfig("")
|
||
|
}
|