Skip to content

Instantly share code, notes, and snippets.

@zwh8800
Created June 22, 2016 07:09
Show Gist options
  • Save zwh8800/3422e23caa5b5e9394622152ff8eda88 to your computer and use it in GitHub Desktop.
Save zwh8800/3422e23caa5b5e9394622152ff8eda88 to your computer and use it in GitHub Desktop.
美丽的debug
package util
import "encoding/json"
func JsonStringify(obj interface{}, intent bool) string {
if intent {
data, err := json.MarshalIndent(obj, "", " ")
if err != nil {
return ""
}
return string(data)
} else {
data, err := json.Marshal(obj)
if err != nil {
return ""
}
return string(data)
}
}
package main
func main() {
someComplicatedVar := make(map[string][]*SomeComplicatedStruct, 0)
someOrmLib.Select().Into(someComplicatedVar)
// when debug
// awful: "someComplicatedVar: { "a": [0x12344321, 0x12344322] }"
glog.Infoln("someComplicatedVar:", someComplicatedVar)
/*
awesome: "{ "a": [{
"Id": 5740,
"Uuid": "619cd38fa263",
"RestaurantId": 385758,
"Removed": false
}, {
"Id": 5745,
"Uuid": "619cd38fa233",
"RestaurantId": 345378,
"Removed": false
}]}"
*/
glog.Infoln("someComplicatedVar:", util.JsonStringify(someComplicatedVar, false))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment