go内置的fmt.sprintf已經很強大了,但是和spew比起來還是相形見绌,這裡來一個例子.
import (
"fmt"
"github.com/davecgh/go-spew/spew"
)
func main() {
scs := spew.ConfigState{Indent: "\t"}
// Output using the ConfigState instance.
v := map[string]int{"one": 1}
fmt.Printf("v: %v\n", v)
scs.Dump(v)
}
對比一下,看看輸出有多美:
v: map[one:1]
(map[string]int) (len=1) {
(string) (len=3) "one": (int) 1
}