go内置的fmt.sprintf已经很强大了,但是和spew比起来还是相形见绌,这里来一个例子.
import (
"fmt"
"github.com/davecgh/go-spew/spew"
)
func main() {
scs := spew.ConfigState{Indent: " "}
// Output using the ConfigState instance.
v := map[string]int{"one": 1}
fmt.Printf("v: %v
", v)
scs.Dump(v)
}
对比一下,看看输出有多美:
v: map[one:1]
(map[string]int) (len=1) {
(string) (len=3) "one": (int) 1
}