-
-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathjson.go
More file actions
29 lines (26 loc) · 944 Bytes
/
json.go
File metadata and controls
29 lines (26 loc) · 944 Bytes
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
package telego
import "github.com/mymmrac/telego/internal/json"
// SetJSONMarshal set JSON marshal func used in Telego
//
// Warning: Panics if passed func is nil
//
// Warning: This method is not concurrently-safe, do not call if bot is already running
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
//
// Warning: This method is not concurrently-safe, do not call if bot is already running
func SetJSONUnmarshal(unmarshal func(data []byte, v any) error) {
if unmarshal == nil {
panic("Telego: nil unmarshal func not allowed")
}
json.Unmarshal = unmarshal
}