Compare commits
No commits in common. "5b8d7ebf876f90cc6f1379ea17b213a8bd9d3692" and "29a3f73f15ba9daa8c9bad5b3d52be156361ef03" have entirely different histories.
5b8d7ebf87
...
29a3f73f15
2
go.mod
2
go.mod
@ -14,7 +14,7 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/bytedance/sonic v1.10.1 // indirect
|
||||
github.com/bytedance/sonic v1.10.0 // indirect
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
||||
github.com/chenzhuoyu/iasm v0.9.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -6,8 +6,6 @@ github.com/bytedance/sonic v1.10.0-rc3 h1:uNSnscRapXTwUgTyOF0GVljYD08p9X/Lbr9Mwe
|
||||
github.com/bytedance/sonic v1.10.0-rc3/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
|
||||
github.com/bytedance/sonic v1.10.0 h1:qtNZduETEIWJVIyDl01BeNxur2rW9OwTQ/yBqFRkKEk=
|
||||
github.com/bytedance/sonic v1.10.0/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
|
||||
github.com/bytedance/sonic v1.10.1 h1:7a1wuFXL1cMy7a3f7/VFcEtriuXQnUBhtoVfOZiaysc=
|
||||
github.com/bytedance/sonic v1.10.1/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0=
|
||||
|
@ -1,5 +1,5 @@
|
||||
package goext
|
||||
|
||||
const GoextVersion = "0.0.259"
|
||||
const GoextVersion = "0.0.258"
|
||||
|
||||
const GoextVersionTimestamp = "2023-09-12T10:48:57+0200"
|
||||
const GoextVersionTimestamp = "2023-09-11T11:28:34+0200"
|
||||
|
@ -25,7 +25,7 @@ func (c *Coll[TData]) EnsureInitializedReflection(v TData) {
|
||||
|
||||
m := make(map[string]fullTypeRef)
|
||||
|
||||
c.initFields("", rval.Type(), m, make([]int, 0))
|
||||
c.initFields("", rval, m, make([]int, 0))
|
||||
|
||||
c.implDataTypeMap[rval.Type()] = m
|
||||
}
|
||||
@ -50,17 +50,20 @@ func (c *Coll[TData]) init() {
|
||||
c.implDataTypeMap = make(map[reflect.Type]map[string]fullTypeRef)
|
||||
|
||||
v := reflect.ValueOf(example)
|
||||
c.initFields("", v.Type(), c.dataTypeMap, make([]int, 0))
|
||||
c.initFields("", v, c.dataTypeMap, make([]int, 0))
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (c *Coll[TData]) initFields(prefix string, rtyp reflect.Type, m map[string]fullTypeRef, idxarr []int) {
|
||||
func (c *Coll[TData]) initFields(prefix string, rval reflect.Value, m map[string]fullTypeRef, idxarr []int) {
|
||||
|
||||
rtyp := rval.Type()
|
||||
|
||||
for i := 0; i < rtyp.NumField(); i++ {
|
||||
|
||||
rsfield := rtyp.Field(i)
|
||||
rvfield := rval.Field(i)
|
||||
|
||||
if !rsfield.IsExported() {
|
||||
continue
|
||||
@ -88,21 +91,21 @@ func (c *Coll[TData]) initFields(prefix string, rtyp reflect.Type, m map[string]
|
||||
newIdxArr := langext.ArrCopy(idxarr)
|
||||
newIdxArr = append(newIdxArr, i)
|
||||
|
||||
if langext.InArray("inline", bsontags) && rsfield.Type.Kind() == reflect.Struct {
|
||||
if langext.InArray("inline", bsontags) && rvfield.Kind() == reflect.Struct {
|
||||
|
||||
// pass-through field
|
||||
c.initFields(prefix, rsfield.Type, m, newIdxArr)
|
||||
c.initFields(prefix, rvfield, m, newIdxArr)
|
||||
|
||||
} else {
|
||||
|
||||
if rsfield.Type.Kind() == reflect.Pointer {
|
||||
if rvfield.Type().Kind() == reflect.Pointer {
|
||||
|
||||
m[fullKey] = fullTypeRef{
|
||||
IsPointer: true,
|
||||
RealType: rsfield.Type,
|
||||
Kind: rsfield.Type.Elem().Kind(),
|
||||
Type: rsfield.Type.Elem(),
|
||||
UnderlyingType: reflectext.Underlying(rsfield.Type.Elem()),
|
||||
RealType: rvfield.Type(),
|
||||
Kind: rvfield.Type().Elem().Kind(),
|
||||
Type: rvfield.Type().Elem(),
|
||||
UnderlyingType: reflectext.Underlying(rvfield.Type().Elem()),
|
||||
Name: rsfield.Name,
|
||||
Index: newIdxArr,
|
||||
}
|
||||
@ -111,23 +114,20 @@ func (c *Coll[TData]) initFields(prefix string, rtyp reflect.Type, m map[string]
|
||||
|
||||
m[fullKey] = fullTypeRef{
|
||||
IsPointer: false,
|
||||
RealType: rsfield.Type,
|
||||
Kind: rsfield.Type.Kind(),
|
||||
Type: rsfield.Type,
|
||||
UnderlyingType: reflectext.Underlying(rsfield.Type),
|
||||
RealType: rvfield.Type(),
|
||||
Kind: rvfield.Type().Kind(),
|
||||
Type: rvfield.Type(),
|
||||
UnderlyingType: reflectext.Underlying(rvfield.Type()),
|
||||
Name: rsfield.Name,
|
||||
Index: newIdxArr,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if rsfield.Type.Kind() == reflect.Struct {
|
||||
c.initFields(fullKey+".", rsfield.Type, m, newIdxArr)
|
||||
if rvfield.Kind() == reflect.Struct {
|
||||
c.initFields(fullKey+".", rvfield, m, newIdxArr)
|
||||
}
|
||||
|
||||
if rsfield.Type.Kind() == reflect.Pointer && rsfield.Type.Elem().Kind() == reflect.Struct {
|
||||
c.initFields(fullKey+".", rsfield.Type.Elem(), m, newIdxArr)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,9 +23,6 @@ func TestReflectionGetFieldType(t *testing.T) {
|
||||
Sub struct {
|
||||
A string `bson:"a"`
|
||||
} `bson:"sub"`
|
||||
SubPtr *struct {
|
||||
A string `bson:"a"`
|
||||
} `bson:"subPtr"`
|
||||
Str string `bson:"str"`
|
||||
Ptr *int `bson:"ptr"`
|
||||
MDate rfctime.RFC3339NanoTime `bson:"mdate"`
|
||||
@ -46,11 +43,6 @@ func TestReflectionGetFieldType(t *testing.T) {
|
||||
}{
|
||||
A: "2",
|
||||
},
|
||||
SubPtr: &struct {
|
||||
A string `bson:"a"`
|
||||
}{
|
||||
A: "4",
|
||||
},
|
||||
Str: "3",
|
||||
Ptr: langext.Ptr(4),
|
||||
MDate: t1,
|
||||
@ -90,12 +82,6 @@ func TestReflectionGetFieldType(t *testing.T) {
|
||||
tst.AssertEqual(t, gft("sub.a").IsPointer, false)
|
||||
tst.AssertEqual(t, gfv("sub.a").(string), "2")
|
||||
|
||||
tst.AssertEqual(t, gft("subPtr.a").Kind.String(), "string")
|
||||
tst.AssertEqual(t, gft("subPtr.a").Type.String(), "string")
|
||||
tst.AssertEqual(t, gft("subPtr.a").Name, "A")
|
||||
tst.AssertEqual(t, gft("subPtr.a").IsPointer, false)
|
||||
tst.AssertEqual(t, gfv("subPtr.a").(string), "4")
|
||||
|
||||
tst.AssertEqual(t, gft("str").Kind.String(), "string")
|
||||
tst.AssertEqual(t, gft("str").Type.String(), "string")
|
||||
tst.AssertEqual(t, gft("str").Name, "Str")
|
||||
@ -119,9 +105,6 @@ func TestReflectionGetTokenValueAsMongoType(t *testing.T) {
|
||||
Sub struct {
|
||||
A string `bson:"a"`
|
||||
} `bson:"sub"`
|
||||
SubPtr struct {
|
||||
A string `bson:"a"`
|
||||
} `bson:"subPtr"`
|
||||
Str string `bson:"str"`
|
||||
Ptr *int `bson:"ptr"`
|
||||
Num int `bson:"num"`
|
||||
@ -147,8 +130,6 @@ func TestReflectionGetTokenValueAsMongoType(t *testing.T) {
|
||||
}
|
||||
|
||||
tst.AssertEqual(t, gtvasmt("hello", "str").(string), "hello")
|
||||
tst.AssertEqual(t, gtvasmt("hello", "sub.a").(string), "hello")
|
||||
tst.AssertEqual(t, gtvasmt("hello", "subPtr.a").(string), "hello")
|
||||
tst.AssertEqual(t, gtvasmt("4", "num").(int), 4)
|
||||
tst.AssertEqual(t, gtvasmt("asdf", "_id").(IDType), "asdf")
|
||||
tst.AssertEqual(t, gtvasmt("", "ptr").(*int), nil)
|
||||
|
Loading…
Reference in New Issue
Block a user