Skip to content

Commit

Permalink
support logic math
Browse files Browse the repository at this point in the history
Change-Id: If294541eab4abac2228b900a7bbbfe69f4fe609c
  • Loading branch information
AoranAllen committed Jul 20, 2023
1 parent b0222bc commit 6f15508
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions tools/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ import (
"errors"
"fmt"
"github.com/bytedance/sonic"
"github.com/bytedance/sonic/decoder"
"github.com/bytedance/sonic/encoder"
fastjson "github.com/goccy/go-json"
"strings"
)

var sonicUseInt64 = sonic.Config{
UseInt64: true,
}.Froze()

// ConvToJSONValidStr convert in to json valid string, basic type will use fmt.Sprint,complex type use json marshal
func ConvToJSONValidStr(in interface{}) (string, error) {
if in == nil {
Expand All @@ -49,10 +52,8 @@ func UnmarshalToSliceUseInt64(jsonStr string) ([]interface{}, error) {
if IsBlank(jsonStr) {
return nil, errors.New("json string is empty")
}
dc := decoder.NewDecoder(jsonStr)
dc.UseInt64()
var arr []interface{}
err := dc.Decode(&arr)
err := sonicUseInt64.UnmarshalFromString(jsonStr, &arr)
if err != nil {
return nil, err
}
Expand All @@ -64,10 +65,9 @@ func UnmarshalToMapUseInt64(jsonStr string) (map[string]interface{}, error) {
if IsBlank(jsonStr) {
return nil, errors.New("json string is empty")
}
dc := decoder.NewDecoder(jsonStr)
dc.UseInt64()

var kv map[string]interface{}
err := dc.Decode(&kv)
err := sonicUseInt64.UnmarshalFromString(jsonStr, &kv)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 6f15508

Please sign in to comment.