Skip to content

Commit e1c7161

Browse files
author
Samuel Oechsler
committed
Add valid to custom json functions
1 parent 01d2ef8 commit e1c7161

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# vNext
22

3+
# v1.3.2
4+
5+
- (feature) Add validate mehtod to custom json un/marshall functions
6+
37
# v1.3.1
48

59
- (feature) Add custom json un-/marshall functions

json/valid.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package json
2+
3+
import (
4+
stdjson "encoding/json"
5+
"runtime"
6+
7+
"github.com/Becklyn/go-wire-core/env"
8+
"github.com/bytedance/sonic"
9+
"github.com/goccy/go-json"
10+
)
11+
12+
func Valid(data []byte) bool {
13+
if env.StringWithDefault("JSON_ENCODER", "std") == "std" {
14+
return stdjson.Valid(data)
15+
}
16+
17+
if runtime.GOARCH == "amd64" {
18+
return sonic.Valid(data)
19+
}
20+
21+
return json.Valid(data)
22+
}

0 commit comments

Comments
 (0)