write out json and yaml config files
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
64223c47cd
commit
5f1dde7e27
|
@ -16,6 +16,7 @@ import "flag"
|
|||
import "fmt"
|
||||
import "github.com/gookit/config"
|
||||
import "github.com/gookit/config/yaml"
|
||||
import "github.com/gookit/config/json"
|
||||
|
||||
// import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
|
@ -79,8 +80,10 @@ func parseConfig() {
|
|||
}
|
||||
*/
|
||||
|
||||
// add driver for support yaml content
|
||||
// add driver for support of yaml and json
|
||||
config.AddDriver(yaml.Driver)
|
||||
config.AddDriver(json.Driver)
|
||||
|
||||
config.LoadFiles("config.yml")
|
||||
|
||||
for _, addr := range config.Strings("arr1") {
|
||||
|
@ -91,4 +94,7 @@ func parseConfig() {
|
|||
fmt.Printf("%#v\n",map1)
|
||||
|
||||
log.Println(config.String("map1.key1.jwc1"))
|
||||
|
||||
cloud := config.StringMap("cloud")
|
||||
fmt.Printf("%#v\n",cloud)
|
||||
}
|
||||
|
|
|
@ -4,6 +4,11 @@ baseKey: value2
|
|||
shell: ${SHELL}
|
||||
envKey1: ${NotExist|defValue}
|
||||
|
||||
cloud:
|
||||
v000185.testing.com.customers.wprod.wit.com:
|
||||
port: 3333
|
||||
proto: tcp
|
||||
|
||||
map1:
|
||||
key1:
|
||||
jwc1: jcarr1
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
run:
|
||||
go run *.go
|
28
main.go
28
main.go
|
@ -11,13 +11,7 @@ import "github.com/gookit/config"
|
|||
import "github.com/andlabs/ui"
|
||||
import _ "github.com/andlabs/ui/winmanifest"
|
||||
|
||||
import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
// dns
|
||||
// import "github.com/miekg/dns"
|
||||
|
||||
// reminder to use protobuf
|
||||
// https://github.com/golang/protobuf
|
||||
// import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
// reminder to use this for JSON
|
||||
// https://github.com/tidwall/gjson
|
||||
|
@ -69,6 +63,8 @@ func doGUI() {
|
|||
ui.Main(setupUI)
|
||||
|
||||
log.Println("GUI exited. Not sure what to do here. os.Exit() ?")
|
||||
|
||||
onExit()
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -83,12 +79,24 @@ func main() {
|
|||
// for now, loop until I figure out what to actually do
|
||||
socketToWIT()
|
||||
}
|
||||
}
|
||||
|
||||
// Exit and write out the config
|
||||
// (in yaml and json I guess.)
|
||||
// switch to json once it can be made human readable
|
||||
func onExit() {
|
||||
log.Println("Sleep for 1 second")
|
||||
time.Sleep(1 * 1000 * 1000 * 1000)
|
||||
|
||||
f, err := os.Create("/tmp/cloud-control-panel-test")
|
||||
spew.Dump(err)
|
||||
f, err := os.Create("/tmp/cloud-control-panel.yaml")
|
||||
if err == nil {
|
||||
config.DumpTo(f, "yaml")
|
||||
}
|
||||
|
||||
config.DumpTo(f, "yaml")
|
||||
f, err = os.Create("/tmp/cloud-control-panel.json")
|
||||
if err == nil {
|
||||
config.DumpTo(f, "json")
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue