Valast converts Go values at runtime into their go/ast equivalent, e.g.:
x := &foo.Bar{
a: "hello world!",
B: 1.234,
}
fmt.Println(valast.String(x))
Prints string:
&foo.Bar{a: "hello world!", B: 1.234}
This can be useful for debugging and testing, you may think of it as a more comprehensive and configurable version of the fmt package's %+v and %#v formatting directives. It is similar to e.g. repr in Python.
go/ast, defers formatting to the best-in-class Go formatter gofumpt.&"foo" properly, and even finding bugs in alternative packages').valast.RegisterType(...).The following are alternatives to Valast, making note of the differences we found that let us to create Valast:
go/ast.&23, whereas Valast will emit a valid expression valast.Addr(23).(int)), not via a go/ast.You may also wish to look at autogold and go-cmp, which aim to solve the "compare Go values in a test" problem.
Overall
Maintained
Code review
Go module
Latest release
Releases this year
3,417 followers · starred Nov 2021
2,541 followers · starred Dec 2020
1,274 followers · starred Feb 2023
161 followers · starred Jan 2021
Valast converts Go values at runtime into their go/ast equivalent, e.g.:
x := &foo.Bar{
a: "hello world!",
B: 1.234,
}
fmt.Println(valast.String(x))
Prints string:
&foo.Bar{a: "hello world!", B: 1.234}
This can be useful for debugging and testing, you may think of it as a more comprehensive and configurable version of the fmt package's %+v and %#v formatting directives. It is similar to e.g. repr in Python.
go/ast, defers formatting to the best-in-class Go formatter gofumpt.&"foo" properly, and even finding bugs in alternative packages').valast.RegisterType(...).The following are alternatives to Valast, making note of the differences we found that let us to create Valast:
go/ast.&23, whereas Valast will emit a valid expression valast.Addr(23).(int)), not via a go/ast.You may also wish to look at autogold and go-cmp, which aim to solve the "compare Go values in a test" problem.
Overall
Maintained
Code review
Go module
Latest release
Releases this year
3,417 followers · starred Nov 2021
2,541 followers · starred Dec 2020
1,274 followers · starred Feb 2023
161 followers · starred Jan 2021