Skip to content

Commit

Permalink
replace json.Unmarshal with json.UnmarshalUseNumber for packages
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed May 15, 2021
1 parent facb294 commit 7003c28
Show file tree
Hide file tree
Showing 87 changed files with 243 additions and 198 deletions.
2 changes: 1 addition & 1 deletion .example/container/garray/json_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ func main() {
Scores *garray.IntArray
}
s := Student{}
json.Unmarshal(b, &s)
json.UnmarshalUseNumber(b, &s)
fmt.Println(s)
}
2 changes: 1 addition & 1 deletion .example/container/glist/json_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ func main() {
Scores *glist.List
}
s := Student{}
json.Unmarshal(b, &s)
json.UnmarshalUseNumber(b, &s)
fmt.Println(s)
}
2 changes: 1 addition & 1 deletion .example/container/gmap/gmap_json_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import (
func main() {
m := gmap.Map{}
s := []byte(`{"name":"john","score":100}`)
json.Unmarshal(s, &m)
json.UnmarshalUseNumber(s, &m)
fmt.Println(m.Map())
}
2 changes: 1 addition & 1 deletion .example/container/gset/json_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ func main() {
Scores *gset.IntSet
}
s := Student{}
json.Unmarshal(b, &s)
json.UnmarshalUseNumber(b, &s)
fmt.Println(s)
}
2 changes: 1 addition & 1 deletion .example/container/gtype/json_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ func main() {
Scores *gtype.Interface
}
s := Student{}
json.Unmarshal(b, &s)
json.UnmarshalUseNumber(b, &s)
fmt.Println(s)
}
2 changes: 1 addition & 1 deletion .example/container/gvar/json_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ func main() {
Scores *g.Var
}
s := Student{}
json.Unmarshal(b, &s)
json.UnmarshalUseNumber(b, &s)
fmt.Println(s)
}
2 changes: 1 addition & 1 deletion .example/encoding/gjson/issue#IZXU2.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ var data = `{

func main() {
struct1 := new(XinYanModel)
err := json.Unmarshal([]byte(data), struct1)
err := json.UnmarshalUseNumber([]byte(data), struct1)
fmt.Println(err)
fmt.Println(struct1)

Expand Down
36 changes: 36 additions & 0 deletions .example/net/ghttp/server/session/redis/redis_bigint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/os/gsession"
)

func main() {
type User struct {
Id int64
Name string
}
s := g.Server()
s.SetSessionStorage(gsession.NewStorageRedis(g.Redis()))
s.Group("/", func(group *ghttp.RouterGroup) {
group.GET("/set", func(r *ghttp.Request) {
user := &User{
Id: 1265476890672672808,
Name: "john",
}
if err := r.Session.Set("user", user); err != nil {
panic(err)
}
r.Response.Write("ok")
})
group.GET("/get", func(r *ghttp.Request) {
r.Response.WriteJson(r.Session.Get("user"))
})
group.GET("/clear", func(r *ghttp.Request) {
r.Session.Clear()
})
})
s.SetPort(8199)
s.Run()
}
2 changes: 1 addition & 1 deletion .example/net/gtcp/pkg_operations/common/funcs/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func RecvPkg(conn *gtcp.Conn) (msg *types.Msg, err error) {
return nil, err
} else {
msg = &types.Msg{}
err = json.Unmarshal(data, msg)
err = json.UnmarshalUseNumber(data, msg)
if err != nil {
return nil, fmt.Errorf("invalid package structure: %s", err.Error())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func main() {
break
}
info := &types.NodeInfo{}
if err := json.Unmarshal(data, info); err != nil {
if err := json.UnmarshalUseNumber(data, info); err != nil {
glog.Errorf("invalid package structure: %s", err.Error())
} else {
glog.Println(info)
Expand Down
4 changes: 2 additions & 2 deletions container/garray/garray_normal_any.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ func (a *Array) UnmarshalJSON(b []byte) error {
}
a.mu.Lock()
defer a.mu.Unlock()
if err := json.Unmarshal(b, &a.array); err != nil {
if err := json.UnmarshalUseNumber(b, &a.array); err != nil {
return err
}
return nil
Expand All @@ -748,7 +748,7 @@ func (a *Array) UnmarshalValue(value interface{}) error {
defer a.mu.Unlock()
switch value.(type) {
case string, []byte:
return json.Unmarshal(gconv.Bytes(value), &a.array)
return json.UnmarshalUseNumber(gconv.Bytes(value), &a.array)
default:
a.array = gconv.SliceAny(value)
}
Expand Down
4 changes: 2 additions & 2 deletions container/garray/garray_normal_int.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ func (a *IntArray) UnmarshalJSON(b []byte) error {
}
a.mu.Lock()
defer a.mu.Unlock()
if err := json.Unmarshal(b, &a.array); err != nil {
if err := json.UnmarshalUseNumber(b, &a.array); err != nil {
return err
}
return nil
Expand All @@ -747,7 +747,7 @@ func (a *IntArray) UnmarshalValue(value interface{}) error {
defer a.mu.Unlock()
switch value.(type) {
case string, []byte:
return json.Unmarshal(gconv.Bytes(value), &a.array)
return json.UnmarshalUseNumber(gconv.Bytes(value), &a.array)
default:
a.array = gconv.SliceInt(value)
}
Expand Down
4 changes: 2 additions & 2 deletions container/garray/garray_normal_str.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ func (a *StrArray) UnmarshalJSON(b []byte) error {
}
a.mu.Lock()
defer a.mu.Unlock()
if err := json.Unmarshal(b, &a.array); err != nil {
if err := json.UnmarshalUseNumber(b, &a.array); err != nil {
return err
}
return nil
Expand All @@ -762,7 +762,7 @@ func (a *StrArray) UnmarshalValue(value interface{}) error {
defer a.mu.Unlock()
switch value.(type) {
case string, []byte:
return json.Unmarshal(gconv.Bytes(value), &a.array)
return json.UnmarshalUseNumber(gconv.Bytes(value), &a.array)
default:
a.array = gconv.SliceStr(value)
}
Expand Down
4 changes: 2 additions & 2 deletions container/garray/garray_sorted_any.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ func (a *SortedArray) UnmarshalJSON(b []byte) error {
}
a.mu.Lock()
defer a.mu.Unlock()
if err := json.Unmarshal(b, &a.array); err != nil {
if err := json.UnmarshalUseNumber(b, &a.array); err != nil {
return err
}
if a.comparator != nil && a.array != nil {
Expand All @@ -706,7 +706,7 @@ func (a *SortedArray) UnmarshalValue(value interface{}) (err error) {
defer a.mu.Unlock()
switch value.(type) {
case string, []byte:
err = json.Unmarshal(gconv.Bytes(value), &a.array)
err = json.UnmarshalUseNumber(gconv.Bytes(value), &a.array)
default:
a.array = gconv.SliceAny(value)
}
Expand Down
4 changes: 2 additions & 2 deletions container/garray/garray_sorted_int.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ func (a *SortedIntArray) UnmarshalJSON(b []byte) error {
}
a.mu.Lock()
defer a.mu.Unlock()
if err := json.Unmarshal(b, &a.array); err != nil {
if err := json.UnmarshalUseNumber(b, &a.array); err != nil {
return err
}
if a.array != nil {
Expand All @@ -676,7 +676,7 @@ func (a *SortedIntArray) UnmarshalValue(value interface{}) (err error) {
defer a.mu.Unlock()
switch value.(type) {
case string, []byte:
err = json.Unmarshal(gconv.Bytes(value), &a.array)
err = json.UnmarshalUseNumber(gconv.Bytes(value), &a.array)
default:
a.array = gconv.SliceInt(value)
}
Expand Down
4 changes: 2 additions & 2 deletions container/garray/garray_sorted_str.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ func (a *SortedStrArray) UnmarshalJSON(b []byte) error {
}
a.mu.Lock()
defer a.mu.Unlock()
if err := json.Unmarshal(b, &a.array); err != nil {
if err := json.UnmarshalUseNumber(b, &a.array); err != nil {
return err
}
if a.array != nil {
Expand All @@ -689,7 +689,7 @@ func (a *SortedStrArray) UnmarshalValue(value interface{}) (err error) {
defer a.mu.Unlock()
switch value.(type) {
case string, []byte:
err = json.Unmarshal(gconv.Bytes(value), &a.array)
err = json.UnmarshalUseNumber(gconv.Bytes(value), &a.array)
default:
a.array = gconv.SliceStr(value)
}
Expand Down
12 changes: 6 additions & 6 deletions container/garray/garray_z_unit_normal_any_array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,12 +570,12 @@ func TestArray_Json(t *testing.T) {
t.Assert(err1, err2)

a2 := garray.New()
err2 = json.Unmarshal(b2, &a2)
err2 = json.UnmarshalUseNumber(b2, &a2)
t.Assert(err2, nil)
t.Assert(a2.Slice(), s1)

var a3 garray.Array
err := json.Unmarshal(b2, &a3)
err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil)
t.Assert(a3.Slice(), s1)
})
Expand All @@ -589,12 +589,12 @@ func TestArray_Json(t *testing.T) {
t.Assert(err1, err2)

a2 := garray.New()
err2 = json.Unmarshal(b2, &a2)
err2 = json.UnmarshalUseNumber(b2, &a2)
t.Assert(err2, nil)
t.Assert(a2.Slice(), s1)

var a3 garray.Array
err := json.Unmarshal(b2, &a3)
err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil)
t.Assert(a3.Slice(), s1)
})
Expand All @@ -612,7 +612,7 @@ func TestArray_Json(t *testing.T) {
t.Assert(err, nil)

user := new(User)
err = json.Unmarshal(b, user)
err = json.UnmarshalUseNumber(b, user)
t.Assert(err, nil)
t.Assert(user.Name, data["Name"])
t.Assert(user.Scores, data["Scores"])
Expand All @@ -631,7 +631,7 @@ func TestArray_Json(t *testing.T) {
t.Assert(err, nil)

user := new(User)
err = json.Unmarshal(b, user)
err = json.UnmarshalUseNumber(b, user)
t.Assert(err, nil)
t.Assert(user.Name, data["Name"])
t.Assert(user.Scores, data["Scores"])
Expand Down
12 changes: 6 additions & 6 deletions container/garray/garray_z_unit_normal_int_array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,11 @@ func TestIntArray_Json(t *testing.T) {
t.Assert(err1, err2)

a2 := garray.NewIntArray()
err1 = json.Unmarshal(b2, &a2)
err1 = json.UnmarshalUseNumber(b2, &a2)
t.Assert(a2.Slice(), s1)

var a3 garray.IntArray
err := json.Unmarshal(b2, &a3)
err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil)
t.Assert(a3.Slice(), s1)
})
Expand All @@ -633,11 +633,11 @@ func TestIntArray_Json(t *testing.T) {
t.Assert(err1, err2)

a2 := garray.NewIntArray()
err1 = json.Unmarshal(b2, &a2)
err1 = json.UnmarshalUseNumber(b2, &a2)
t.Assert(a2.Slice(), s1)

var a3 garray.IntArray
err := json.Unmarshal(b2, &a3)
err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil)
t.Assert(a3.Slice(), s1)
})
Expand All @@ -655,7 +655,7 @@ func TestIntArray_Json(t *testing.T) {
t.Assert(err, nil)

user := new(User)
err = json.Unmarshal(b, user)
err = json.UnmarshalUseNumber(b, user)
t.Assert(err, nil)
t.Assert(user.Name, data["Name"])
t.Assert(user.Scores, data["Scores"])
Expand All @@ -674,7 +674,7 @@ func TestIntArray_Json(t *testing.T) {
t.Assert(err, nil)

user := new(User)
err = json.Unmarshal(b, user)
err = json.UnmarshalUseNumber(b, user)
t.Assert(err, nil)
t.Assert(user.Name, data["Name"])
t.Assert(user.Scores, data["Scores"])
Expand Down
12 changes: 6 additions & 6 deletions container/garray/garray_z_unit_normal_str_array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,11 @@ func TestStrArray_Json(t *testing.T) {
t.Assert(err1, err2)

a2 := garray.NewStrArray()
err1 = json.Unmarshal(b2, &a2)
err1 = json.UnmarshalUseNumber(b2, &a2)
t.Assert(a2.Slice(), s1)

var a3 garray.StrArray
err := json.Unmarshal(b2, &a3)
err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil)
t.Assert(a3.Slice(), s1)
})
Expand All @@ -632,11 +632,11 @@ func TestStrArray_Json(t *testing.T) {
t.Assert(err1, err2)

a2 := garray.NewStrArray()
err1 = json.Unmarshal(b2, &a2)
err1 = json.UnmarshalUseNumber(b2, &a2)
t.Assert(a2.Slice(), s1)

var a3 garray.StrArray
err := json.Unmarshal(b2, &a3)
err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil)
t.Assert(a3.Slice(), s1)
})
Expand All @@ -654,7 +654,7 @@ func TestStrArray_Json(t *testing.T) {
t.Assert(err, nil)

user := new(User)
err = json.Unmarshal(b, user)
err = json.UnmarshalUseNumber(b, user)
t.Assert(err, nil)
t.Assert(user.Name, data["Name"])
t.Assert(user.Scores, data["Scores"])
Expand All @@ -673,7 +673,7 @@ func TestStrArray_Json(t *testing.T) {
t.Assert(err, nil)

user := new(User)
err = json.Unmarshal(b, user)
err = json.UnmarshalUseNumber(b, user)
t.Assert(err, nil)
t.Assert(user.Name, data["Name"])
t.Assert(user.Scores, data["Scores"])
Expand Down
Loading

0 comments on commit 7003c28

Please sign in to comment.