update field (#8)
Reviewed-on: #8 Co-authored-by: andrey <andrey@4devs.io> Co-committed-by: andrey <andrey@4devs.io>
This commit was merged in pull request #8.
This commit is contained in:
23
field/encoder_json.go
Normal file
23
field/encoder_json.go
Normal file
@@ -0,0 +1,23 @@
|
||||
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...)
|
||||
}
|
||||
Reference in New Issue
Block a user