mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-17 03:42:26 +08:00
update vendor
This commit is contained in:
19
vendor/github.com/qiniu/x/jsonutil.v7/unmarshal_string.go
generated
vendored
Normal file
19
vendor/github.com/qiniu/x/jsonutil.v7/unmarshal_string.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
package jsonutil
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// ----------------------------------------------------------
|
||||
|
||||
func Unmarshal(data string, v interface{}) error {
|
||||
|
||||
sh := *(*reflect.StringHeader)(unsafe.Pointer(&data))
|
||||
arr := (*[1<<30]byte)(unsafe.Pointer(sh.Data))
|
||||
return json.Unmarshal(arr[:sh.Len], v)
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------
|
||||
|
||||
19
vendor/github.com/qiniu/x/jsonutil.v7/unmarshal_test.go
generated
vendored
Normal file
19
vendor/github.com/qiniu/x/jsonutil.v7/unmarshal_test.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
package jsonutil
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test(t *testing.T) {
|
||||
|
||||
var ret struct {
|
||||
Id string `json:"id"`
|
||||
}
|
||||
err := Unmarshal(`{"id": "123"}`, &ret)
|
||||
if err != nil {
|
||||
t.Fatal("Unmarshal failed:", err)
|
||||
}
|
||||
if ret.Id != "123" {
|
||||
t.Fatal("Unmarshal uncorrect:", ret.Id)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user