How to pretty print variables

前端 未结 3 693
执念已碎
执念已碎 2020-12-13 06:25

Is there something like Ruby\'s awesome_print in Go?

For example in Ruby you could write:

require \'ap\'
x = {a:1,b:2} // also works for         


        
3条回答
  •  庸人自扰
    2020-12-13 06:51

    Nevermind, I found one: https://github.com/davecgh/go-spew

    // import "github.com/davecgh/go-spew/spew"
    x := map[string]interface{}{"a":1,"b":2}
    spew.Dump(x)
    

    Would give an output:

    (map[string]interface {}) (len=2) {
     (string) (len=1) "a": (int) 1,
     (string) (len=1) "b": (int) 2
    }
    

提交回复
热议问题