-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
json.go
27 lines (22 loc) · 764 Bytes
/
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
package telego
import "github.com/mymmrac/telego/internal/json"
// SetJSONMarshal set JSON marshal func used in Telego
//
// Warning: Panics if passed func is nil
func SetJSONMarshal(marshal func(v any) ([]byte, error)) {
if marshal == nil {
panic("Telego: nil marshal func not allowed")
}
json.Marshal = marshal
}
// SetJSONUnmarshal set JSON unmarshal func used in Telego
// Note: Unmarshal func should support unmarshalling into interface types if the struct field is populated with
// the correct type, not all libraries support this
//
// Warning: Panics if passed func is nil
func SetJSONUnmarshal(unmarshal func(data []byte, v any) error) {
if unmarshal == nil {
panic("Telego: nil unmarshal func not allowed")
}
json.Unmarshal = unmarshal
}