Reviewed-on: #8 Co-authored-by: andrey <andrey@4devs.io> Co-committed-by: andrey <andrey@4devs.io>
24 lines
473 B
Go
24 lines
473 B
Go
package field
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strconv"
|
|
)
|
|
|
|
func NewEncoderJSON(opts ...func(*BaseEncoder)) BaseEncoder {
|
|
opts = append([]func(*BaseEncoder){
|
|
WithAppendString(strconv.AppendQuote),
|
|
WithDelimeter(':'),
|
|
WithDefaultValue(func(dst []byte, e Encoder, val Value) []byte {
|
|
js, err := json.Marshal(val.Any())
|
|
if err != nil {
|
|
return e.AppendValue(dst, ErrorValue(err))
|
|
}
|
|
|
|
return append(dst, js...)
|
|
}),
|
|
}, opts...)
|
|
|
|
return NewEncoder(opts...)
|
|
}
|