Skip to content

Instantly share code, notes, and snippets.

@jihuichoi
Last active August 31, 2019 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jihuichoi/2e450edd08ca5adaf429688c8ce38941 to your computer and use it in GitHub Desktop.
Save jihuichoi/2e450edd08ca5adaf429688c8ce38941 to your computer and use it in GitHub Desktop.
go struct 를 json 형식으로 보기 좋게 출력함. stdout
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