add source with func name
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package field
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
@@ -8,8 +9,18 @@ func NewEncoderText(opts ...func(*BaseEncoder)) BaseEncoder {
|
||||
opts = append([]func(*BaseEncoder){
|
||||
WithGropuConfig(0, 0, ' '),
|
||||
WithNullValue("<nil>"),
|
||||
WithDefaultValue(func(dst []byte, _ Encoder, val Value) []byte {
|
||||
return fmt.Appendf(dst, "%+v", val.Any())
|
||||
WithDefaultValue(func(dst []byte, enc Encoder, val Value) []byte {
|
||||
switch value := val.Any().(type) {
|
||||
case encoding.TextMarshaler:
|
||||
data, err := value.MarshalText()
|
||||
if err != nil {
|
||||
return enc.AppendValue(dst, ErrorValue(err))
|
||||
}
|
||||
|
||||
return enc.AppendValue(dst, StringValue(string(data)))
|
||||
default:
|
||||
return fmt.Appendf(dst, "%+v", val.Any())
|
||||
}
|
||||
}),
|
||||
}, opts...)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user