-
Notifications
You must be signed in to change notification settings - Fork 2
/
fmt_json.go
34 lines (29 loc) · 901 Bytes
/
fmt_json.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2022 GoFast Author(http://chende.ren). All rights reserved.
// Use of this source code is governed by a MIT license
package mapx
import (
"github.com/qinchende/gofast/skill/jsonx"
"io"
)
// +++ JSON Bytes
func BindJsonBytes(dst any, content []byte, like int8) error {
return BindJsonBytesX(dst, content, matchOptions(like))
}
func BindJsonBytesX(dst any, content []byte, opts *BindOptions) error {
var kv map[string]any
if err := jsonx.Unmarshal(&kv, content); err != nil {
return err
}
return BindKVX(dst, kv, opts)
}
// +++ JSON Reader
func BindJsonReader(dst any, reader io.Reader, like int8) error {
return BindJsonReaderX(dst, reader, matchOptions(like))
}
func BindJsonReaderX(dst any, reader io.Reader, opts *BindOptions) error {
var kv map[string]any
if err := jsonx.UnmarshalFromReader(&kv, reader); err != nil {
return err
}
return BindKVX(dst, kv, opts)
}