From 7d0a52729d37d4e137b142f6ce0cb95a90aadc1a Mon Sep 17 00:00:00 2001 From: superwhiskers Date: Sun, 22 Apr 2018 21:35:50 +0000 Subject: [PATCH] prettify the config before writing --- fs.go | 2 +- setup.go | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/fs.go b/fs.go index 3cc40cc..182a148 100644 --- a/fs.go +++ b/fs.go @@ -266,7 +266,7 @@ func readJSONFile(file string) map[string]interface{} { func writeJSONFile(file string, data map[string]interface{}) { // turn go map into valid JSON - fileData, err := json.Marshal(data) + fileData, err := json.MarshalIndent(data, "", " ") // handle errors if err != nil { diff --git a/setup.go b/setup.go index a88f0d3..9c61c97 100644 --- a/setup.go +++ b/setup.go @@ -217,12 +217,12 @@ func doCertGen(config string) { if enableHTTPS == "y" { // enable https in the config - configData["https"] = true + configData["config"].(map[string]interface{})["https"] = true } else if enableHTTPS == "n" { // keep https disabled - configData["https"] = false + configData["config"].(map[string]interface{})["https"] = false } @@ -808,7 +808,7 @@ func setup(fileMap map[string]string) { if method != "4" { // prettify the JSON - pretty, err := json.MarshalIndent(config, "", " ") + stringifiedConfig, err := json.MarshalIndent(config, "", " ") // error handling if err != nil { @@ -822,7 +822,7 @@ func setup(fileMap map[string]string) { } // turn it into a string - prettifiedJSON := string(pretty[:]) + stringifiedJSON := string(stringifiedConfig[:]) // confirm the preferences var areSettingsOkay string @@ -842,7 +842,7 @@ func setup(fileMap map[string]string) { fmt.Printf(" make https work \n") fmt.Printf(" profit??? \n") fmt.Printf(" \n") - fmt.Printf(prettifiedJSON) + fmt.Printf(stringifiedJSON) fmt.Printf("\n \n") fmt.Printf("-> (y|n) \n") fmt.Printf("=============================================================\n") @@ -876,9 +876,6 @@ func setup(fileMap map[string]string) { os.Exit(0) } - - // convert golang map to json - stringifiedConfig, err := json.Marshal(config) // error handling if err != nil {