From 84fc164e7f4a19e49def4c6e7acb209f3dc3e9c1 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 23 May 2019 09:47:48 -0700 Subject: [PATCH] crap. the 'config' isn't parsing the JSON files correctly? Signed-off-by: Jeff Carr --- Makefile | 13 +++++++---- config.go | 13 ++++++++++- config.json | 22 ++++++++++++++++++ main.go | 16 +++++++++++-- resources/config.json | 53 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 resources/config.json diff --git a/Makefile b/Makefile index 687ec15..91894f6 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,20 @@ GITCOMMIT = $(shell git rev-list -1 HEAD) GOVERSION = $(shell go version | cut -d' ' -f 3) +BUILDTIME = $(shell date -u --iso-8601=seconds) + +# try go get github.com/ahmetb/govvv +# this will add branch info & build RFC3339 date also + +debug: + @echo your version of go must be greater than 2.10. Your version is ${GOVERSION} + go build -ldflags "-X main.GITCOMMIT=${GITCOMMIT} -X main.GOVERSION='${GOVERSION}' -X main.BUILDTIME='${BUILDTIME}'" + ./cloud-control-panel --debugging run: @echo your version of go must be greater than 2.10. Your version is ${GOVERSION} go build -ldflags "-X main.GITCOMMIT=${GITCOMMIT}" ./cloud-control-panel -debug: - go build -ldflags "-X main.GITCOMMIT=${GITCOMMIT} -X main.GOVERSION='${GOVERSION}'" - ./cloud-control-panel --debugging - nogui: go build ./cloud-control-panel -nogui diff --git a/config.go b/config.go index 29f437a..fc7a469 100644 --- a/config.go +++ b/config.go @@ -14,6 +14,8 @@ import "log" import "os" import "flag" import "fmt" +import "runtime" + import "github.com/gookit/config" import "github.com/gookit/config/yaml" import "github.com/gookit/config/json" @@ -73,7 +75,7 @@ func parseFlags() { config.Set("debugging", debugging) } -func parseConfig() { +func parseConfig(defaultConfig string) { config.WithOptions(config.ParseEnv) parseFlags() @@ -85,6 +87,15 @@ func parseConfig() { config.AddDriver(yaml.Driver) config.AddDriver(json.Driver) + // TODO: figure out how to look for this file in the right + // place under Linux, MacOS and Windows + if runtime.GOOS == "linux" { + log.Println("OS: Linux") + } else if runtime.GOOS == "windows" { + log.Println("OS: Windows") + } else { + log.Println("OS: " + runtime.GOOS) + } config.LoadFiles("config.json") for _, addr := range config.Strings("arr1") { diff --git a/config.json b/config.json index 73fb050..ce1df55 100644 --- a/config.json +++ b/config.json @@ -8,6 +8,28 @@ "docker0" ], "baseKey": "value2", + "accounts": { + "jcarr": { + "hostname": "fire.lab.wit.com", + "domainname": "lab.wit.com", + "port": 3333, + "rows": 18, + "proto": "tcp" + }, + "jcarr2": { + "hostname": "fire.lab.wit.com", + "domainname": "lab.wit.com", + "port": 3333, + "rows": 18, + "proto": "tcp" + }, + "bmath": { + "hostname": "v000185.testing.com.customers.wprod.wit.com", + "domainname": "testing.com.customers.wprod.wit.com", + "port": 9000, + "proto": "tcp" + } + }, "cloud": { "jcarr": { "hostname": "fire.lab.wit.com", diff --git a/main.go b/main.go index 39d8aac..89f0ca2 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import "time" // import "fmt" import "github.com/gookit/config" +import "github.com/gobuffalo/packr" import "git.wit.com/wit/gui" @@ -51,7 +52,13 @@ func onExit() { } func main() { - parseConfig() + // This puts all the files in that directory in the binary + // This directory includes the default config file if there is not already one + box := packr.NewBox("./resources") + defaultConfig, _ := box.FindString("cloud.json") + + // This will parse the command line and config file + parseConfig(defaultConfig) // only test the socket code if no GUI if (config.String("nogui") == "true") { @@ -67,7 +74,7 @@ func main() { gui.Data.Width = config.Int("width") gui.Data.Height = config.Int("height") - gui.Data.Version = "v0.4 " + gui.Data.Version = "v0.4" gui.Data.GitCommit = GITCOMMIT gui.Data.GoVersion = GOVERSION gui.Data.ButtonClickNew = buttonClickNew @@ -85,6 +92,11 @@ func buttonClickNew(b *gui.ButtonMap) { if (b.Note == "BACK") { gui.Data.State = "splash" } + if (b.Note == "ADD") { + log.Println("\tSHOULD ADD ACCOUNT HERE") + log.Println("\tSHOULD ADD ACCOUNT HERE") + log.Println("\tSHOULD ADD ACCOUNT HERE") + } if (b.Note == "BMATH") { log.Println("\tTRIGGER BMATH HERE") log.Println("\tTRIGGER BMATH HERE") diff --git a/resources/config.json b/resources/config.json new file mode 100644 index 0000000..3d20046 --- /dev/null +++ b/resources/config.json @@ -0,0 +1,53 @@ +{ + "BUILDDEBUG": "", + "MAIL": "/var/mail/jcarr", + "USER": "jcarr", + "arr1": [ + "lo", + "wifi0", + "docker0" + ], + "baseKey": "value2", + "accounts": { + "jcarr": { + "hostname": "fire.lab.wit.com", + "port": 3333, + "rows": 18, + "proto": "tcp" + }, + "bmath": { + "hostname": "v000185.testing.com.customers.wprod.wit.com", + "domainname": "testing.com.customers.wprod.wit.com", + "port": 9000, + "proto": "tcp" + } + }, + "cloud": { + "jcarr": { + "hostname": "fire.lab.wit.com", + "port": 3333, + "rows": 18, + "proto": "tcp" + }, + "v000185": { + "hostname": "v000185.testing.com.customers.wprod.wit.com", + "port": 3333, + "rows": 567, + "proto": "tcp" + } + }, + "debug": false, + "envKey1": "${NotExist|defValue}", + "height": 600, + "width": 800, + "hostname": "localhost", + "map1": { + "key1": { + "jwc1": "jcarr1", + "jwc2": "jcarr2" + }, + "key2": "val20" + }, + "name": "app2", + "shell": "${SHELL}" +}