You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
473 B
24 lines
473 B
10 months ago
|
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...)
|
||
|
}
|