Last active
August 31, 2019 14:18
-
-
Save jihuichoi/2e450edd08ca5adaf429688c8ce38941 to your computer and use it in GitHub Desktop.
go struct 를 json 형식으로 보기 좋게 출력함. stdout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package utils | |
import ( | |
"encoding/json" | |
"fmt" | |
"strings" | |
) | |
func PrettyPrint(target ...interface{}) { | |
replacer := strings.NewReplacer("\t", " ", "\n", "") | |
for _, t := range target { | |
if _t, ok := t.(string); ok { | |
t = replacer.Replace(_t) | |
} | |
s, _ := json.MarshalIndent(t, "", "\t") | |
fmt.Println(string(s)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment