Skip to content

Commit

Permalink
Add valid to custom json functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Oechsler committed Aug 23, 2023
1 parent 01d2ef8 commit e1c7161
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# vNext

# v1.3.2

- (feature) Add validate mehtod to custom json un/marshall functions

# v1.3.1

- (feature) Add custom json un-/marshall functions
Expand Down
22 changes: 22 additions & 0 deletions json/valid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package json

import (
stdjson "encoding/json"
"runtime"

"github.com/Becklyn/go-wire-core/env"
"github.com/bytedance/sonic"
"github.com/goccy/go-json"
)

func Valid(data []byte) bool {
if env.StringWithDefault("JSON_ENCODER", "std") == "std" {
return stdjson.Valid(data)
}

if runtime.GOARCH == "amd64" {
return sonic.Valid(data)
}

return json.Valid(data)
}

0 comments on commit e1c7161

Please sign in to comment.