Open rsgok opened 2 years ago
Litter doesn't use fmt.Stringer
because Litter is meant to produce a format that corresponds to the data structure. If you want to modify the output, you can plug in a custom formatter. You should easily be able to add something that dumps fmt.Stringer
types as strings instead.
Litter doesn't use
fmt.Stringer
because Litter is meant to produce a format that corresponds to the data structure. If you want to modify the output, you can plug in a custom formatter. You should easily be able to add something that dumpsfmt.Stringer
types as strings instead.
Have tried custom formatter, seems good.
However, when i use anonymous struct member, output is unexpected. Like I mention in https://github.com/davecgh/go-spew/issues/142
Here is my demo code
package main
import (
"io"
"github.com/sanity-io/litter"
)
func main() {
TT()
}
type A struct {
Tag string
Num int
InA
}
type InA struct {
Id int
Type string
}
func (t InA) String() string {
return t.Type
}
func (t InA) LitterDump(w io.Writer) {
w.Write([]byte(t.Type))
}
func TT() {
a := A{
Tag: "tag-A",
Num: 1,
InA: InA{
Id: 100,
Type: "test",
},
}
litter.Dump(a)
}
output is
main.Atest
struct A is missing
Seems like litter not accept costumed String() implement func
Example comparing go-spew
Output compare