goon

本库修改自https://github.com/shurcooL/goon, 由于上面的库常久不更新, 并且我需要做一些小的修改满足需求, 所以fork了自用, 仍采用MIT许可.
主要修改有:
- 增加goon="-"的tag让我们可以对结构体手动控制哪些字段不需要
- 对XXX_开头的字段全都去掉, 这些是protobuf中比较多余的字段
- 对golang特有的枚举做支持
Package goon is a deep pretty printer with Go-like notation. It implements the goon specification.
Installation
go get -u github.com/shurcooL/go-goon
Examples
x := Lang{
Name: "Go",
Year: 2009,
URL: "http",
Inner: &Inner{
Field1: "Secret!",
},
}
goon.Dump(x)
// Output:
// (Lang)(Lang{
// Name: (string)("Go"),
// Year: (int)(2009),
// URL: (string)("http"),
// Inner: (*Inner)(&Inner{
// Field1: (string)("Secret!"),
// Field2: (int)(0),
// }),
// })
items := []int{1, 2, 3}
goon.DumpExpr(len(items))
// Output:
// len(items) = (int)(3)
adderFunc := func(a int, b int) int {
c := a + b
return c
}
goon.DumpExpr(adderFunc)
// Output:
// adderFunc = (func(int, int) int)(func(a int, b int) int {
// c := a + b
// return c
// })
Directories
Path |
Synopsis |
bypass |
Package bypass allows bypassing reflect restrictions on accessing unexported struct fields. |
Attribution
go-goon source was based on the existing source of go-spew by Dave Collins.
License