Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
5b8d7ebf87 | |||
11dc6d2640 | |||
29a3f73f15 | |||
98105642fc |
6
go.mod
6
go.mod
@@ -8,13 +8,13 @@ require (
|
|||||||
github.com/rs/xid v1.5.0
|
github.com/rs/xid v1.5.0
|
||||||
github.com/rs/zerolog v1.30.0
|
github.com/rs/zerolog v1.30.0
|
||||||
go.mongodb.org/mongo-driver v1.12.1
|
go.mongodb.org/mongo-driver v1.12.1
|
||||||
golang.org/x/crypto v0.12.0
|
golang.org/x/crypto v0.13.0
|
||||||
golang.org/x/sys v0.12.0
|
golang.org/x/sys v0.12.0
|
||||||
golang.org/x/term v0.12.0
|
golang.org/x/term v0.12.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/bytedance/sonic v1.10.0 // indirect
|
github.com/bytedance/sonic v1.10.1 // indirect
|
||||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
||||||
github.com/chenzhuoyu/iasm v0.9.0 // indirect
|
github.com/chenzhuoyu/iasm v0.9.0 // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
||||||
@@ -42,7 +42,7 @@ require (
|
|||||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
github.com/xdg-go/stringprep v1.0.4 // indirect
|
||||||
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
|
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
|
||||||
golang.org/x/arch v0.5.0 // indirect
|
golang.org/x/arch v0.5.0 // indirect
|
||||||
golang.org/x/net v0.14.0 // indirect
|
golang.org/x/net v0.15.0 // indirect
|
||||||
golang.org/x/sync v0.3.0 // indirect
|
golang.org/x/sync v0.3.0 // indirect
|
||||||
golang.org/x/text v0.13.0 // indirect
|
golang.org/x/text v0.13.0 // indirect
|
||||||
google.golang.org/protobuf v1.31.0 // indirect
|
google.golang.org/protobuf v1.31.0 // indirect
|
||||||
|
6
go.sum
6
go.sum
@@ -6,6 +6,8 @@ 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-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 h1:qtNZduETEIWJVIyDl01BeNxur2rW9OwTQ/yBqFRkKEk=
|
||||||
github.com/bytedance/sonic v1.10.0/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
|
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-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-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
|
||||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0=
|
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0=
|
||||||
@@ -151,6 +153,8 @@ golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
|
|||||||
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
|
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
|
||||||
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
|
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
|
||||||
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
|
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
|
||||||
|
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
|
||||||
|
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
@@ -163,6 +167,8 @@ golang.org/x/net v0.13.0 h1:Nvo8UFsZ8X3BhAC9699Z1j7XQ3rsZnUUm7jfBEk1ueY=
|
|||||||
golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
|
golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
|
||||||
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
|
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
|
||||||
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
|
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
|
||||||
|
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
|
||||||
|
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
package goext
|
package goext
|
||||||
|
|
||||||
const GoextVersion = "0.0.257"
|
const GoextVersion = "0.0.259"
|
||||||
|
|
||||||
const GoextVersionTimestamp = "2023-09-05T15:01:55+0200"
|
const GoextVersionTimestamp = "2023-09-12T10:48:57+0200"
|
||||||
|
@@ -21,19 +21,7 @@ func (c *Coll[TData]) List(ctx context.Context, filter ct.Filter, pageSize *int,
|
|||||||
|
|
||||||
if filter != nil {
|
if filter != nil {
|
||||||
pipeline = filter.FilterQuery()
|
pipeline = filter.FilterQuery()
|
||||||
fpf1, fpd1, fpf2, fpd2 := filter.Pagination()
|
pf1, pd1, pf2, pd2 = filter.Pagination()
|
||||||
if fpf1 != "" {
|
|
||||||
pf1 = fpf1
|
|
||||||
}
|
|
||||||
if fpd1 != "" {
|
|
||||||
pd1 = fpd1
|
|
||||||
}
|
|
||||||
if fpf2 != "" {
|
|
||||||
pf2 = fpf2
|
|
||||||
}
|
|
||||||
if fpd2 != "" {
|
|
||||||
pd2 = fpd2
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sortPrimary := pf1
|
sortPrimary := pf1
|
||||||
|
@@ -25,7 +25,7 @@ func (c *Coll[TData]) EnsureInitializedReflection(v TData) {
|
|||||||
|
|
||||||
m := make(map[string]fullTypeRef)
|
m := make(map[string]fullTypeRef)
|
||||||
|
|
||||||
c.initFields("", rval, m, make([]int, 0))
|
c.initFields("", rval.Type(), m, make([]int, 0))
|
||||||
|
|
||||||
c.implDataTypeMap[rval.Type()] = m
|
c.implDataTypeMap[rval.Type()] = m
|
||||||
}
|
}
|
||||||
@@ -50,20 +50,17 @@ func (c *Coll[TData]) init() {
|
|||||||
c.implDataTypeMap = make(map[reflect.Type]map[string]fullTypeRef)
|
c.implDataTypeMap = make(map[reflect.Type]map[string]fullTypeRef)
|
||||||
|
|
||||||
v := reflect.ValueOf(example)
|
v := reflect.ValueOf(example)
|
||||||
c.initFields("", v, c.dataTypeMap, make([]int, 0))
|
c.initFields("", v.Type(), c.dataTypeMap, make([]int, 0))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Coll[TData]) initFields(prefix string, rval reflect.Value, m map[string]fullTypeRef, idxarr []int) {
|
func (c *Coll[TData]) initFields(prefix string, rtyp reflect.Type, m map[string]fullTypeRef, idxarr []int) {
|
||||||
|
|
||||||
rtyp := rval.Type()
|
|
||||||
|
|
||||||
for i := 0; i < rtyp.NumField(); i++ {
|
for i := 0; i < rtyp.NumField(); i++ {
|
||||||
|
|
||||||
rsfield := rtyp.Field(i)
|
rsfield := rtyp.Field(i)
|
||||||
rvfield := rval.Field(i)
|
|
||||||
|
|
||||||
if !rsfield.IsExported() {
|
if !rsfield.IsExported() {
|
||||||
continue
|
continue
|
||||||
@@ -91,21 +88,21 @@ func (c *Coll[TData]) initFields(prefix string, rval reflect.Value, m map[string
|
|||||||
newIdxArr := langext.ArrCopy(idxarr)
|
newIdxArr := langext.ArrCopy(idxarr)
|
||||||
newIdxArr = append(newIdxArr, i)
|
newIdxArr = append(newIdxArr, i)
|
||||||
|
|
||||||
if langext.InArray("inline", bsontags) && rvfield.Kind() == reflect.Struct {
|
if langext.InArray("inline", bsontags) && rsfield.Type.Kind() == reflect.Struct {
|
||||||
|
|
||||||
// pass-through field
|
// pass-through field
|
||||||
c.initFields(prefix, rvfield, m, newIdxArr)
|
c.initFields(prefix, rsfield.Type, m, newIdxArr)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if rvfield.Type().Kind() == reflect.Pointer {
|
if rsfield.Type.Kind() == reflect.Pointer {
|
||||||
|
|
||||||
m[fullKey] = fullTypeRef{
|
m[fullKey] = fullTypeRef{
|
||||||
IsPointer: true,
|
IsPointer: true,
|
||||||
RealType: rvfield.Type(),
|
RealType: rsfield.Type,
|
||||||
Kind: rvfield.Type().Elem().Kind(),
|
Kind: rsfield.Type.Elem().Kind(),
|
||||||
Type: rvfield.Type().Elem(),
|
Type: rsfield.Type.Elem(),
|
||||||
UnderlyingType: reflectext.Underlying(rvfield.Type().Elem()),
|
UnderlyingType: reflectext.Underlying(rsfield.Type.Elem()),
|
||||||
Name: rsfield.Name,
|
Name: rsfield.Name,
|
||||||
Index: newIdxArr,
|
Index: newIdxArr,
|
||||||
}
|
}
|
||||||
@@ -114,20 +111,23 @@ func (c *Coll[TData]) initFields(prefix string, rval reflect.Value, m map[string
|
|||||||
|
|
||||||
m[fullKey] = fullTypeRef{
|
m[fullKey] = fullTypeRef{
|
||||||
IsPointer: false,
|
IsPointer: false,
|
||||||
RealType: rvfield.Type(),
|
RealType: rsfield.Type,
|
||||||
Kind: rvfield.Type().Kind(),
|
Kind: rsfield.Type.Kind(),
|
||||||
Type: rvfield.Type(),
|
Type: rsfield.Type,
|
||||||
UnderlyingType: reflectext.Underlying(rvfield.Type()),
|
UnderlyingType: reflectext.Underlying(rsfield.Type),
|
||||||
Name: rsfield.Name,
|
Name: rsfield.Name,
|
||||||
Index: newIdxArr,
|
Index: newIdxArr,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if rvfield.Kind() == reflect.Struct {
|
if rsfield.Type.Kind() == reflect.Struct {
|
||||||
c.initFields(fullKey+".", rvfield, m, newIdxArr)
|
c.initFields(fullKey+".", rsfield.Type, m, newIdxArr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rsfield.Type.Kind() == reflect.Pointer && rsfield.Type.Elem().Kind() == reflect.Struct {
|
||||||
|
c.initFields(fullKey+".", rsfield.Type.Elem(), m, newIdxArr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -23,6 +23,9 @@ func TestReflectionGetFieldType(t *testing.T) {
|
|||||||
Sub struct {
|
Sub struct {
|
||||||
A string `bson:"a"`
|
A string `bson:"a"`
|
||||||
} `bson:"sub"`
|
} `bson:"sub"`
|
||||||
|
SubPtr *struct {
|
||||||
|
A string `bson:"a"`
|
||||||
|
} `bson:"subPtr"`
|
||||||
Str string `bson:"str"`
|
Str string `bson:"str"`
|
||||||
Ptr *int `bson:"ptr"`
|
Ptr *int `bson:"ptr"`
|
||||||
MDate rfctime.RFC3339NanoTime `bson:"mdate"`
|
MDate rfctime.RFC3339NanoTime `bson:"mdate"`
|
||||||
@@ -43,6 +46,11 @@ func TestReflectionGetFieldType(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
A: "2",
|
A: "2",
|
||||||
},
|
},
|
||||||
|
SubPtr: &struct {
|
||||||
|
A string `bson:"a"`
|
||||||
|
}{
|
||||||
|
A: "4",
|
||||||
|
},
|
||||||
Str: "3",
|
Str: "3",
|
||||||
Ptr: langext.Ptr(4),
|
Ptr: langext.Ptr(4),
|
||||||
MDate: t1,
|
MDate: t1,
|
||||||
@@ -82,6 +90,12 @@ func TestReflectionGetFieldType(t *testing.T) {
|
|||||||
tst.AssertEqual(t, gft("sub.a").IsPointer, false)
|
tst.AssertEqual(t, gft("sub.a").IsPointer, false)
|
||||||
tst.AssertEqual(t, gfv("sub.a").(string), "2")
|
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").Kind.String(), "string")
|
||||||
tst.AssertEqual(t, gft("str").Type.String(), "string")
|
tst.AssertEqual(t, gft("str").Type.String(), "string")
|
||||||
tst.AssertEqual(t, gft("str").Name, "Str")
|
tst.AssertEqual(t, gft("str").Name, "Str")
|
||||||
@@ -105,6 +119,9 @@ func TestReflectionGetTokenValueAsMongoType(t *testing.T) {
|
|||||||
Sub struct {
|
Sub struct {
|
||||||
A string `bson:"a"`
|
A string `bson:"a"`
|
||||||
} `bson:"sub"`
|
} `bson:"sub"`
|
||||||
|
SubPtr struct {
|
||||||
|
A string `bson:"a"`
|
||||||
|
} `bson:"subPtr"`
|
||||||
Str string `bson:"str"`
|
Str string `bson:"str"`
|
||||||
Ptr *int `bson:"ptr"`
|
Ptr *int `bson:"ptr"`
|
||||||
Num int `bson:"num"`
|
Num int `bson:"num"`
|
||||||
@@ -130,6 +147,8 @@ func TestReflectionGetTokenValueAsMongoType(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tst.AssertEqual(t, gtvasmt("hello", "str").(string), "hello")
|
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("4", "num").(int), 4)
|
||||||
tst.AssertEqual(t, gtvasmt("asdf", "_id").(IDType), "asdf")
|
tst.AssertEqual(t, gtvasmt("asdf", "_id").(IDType), "asdf")
|
||||||
tst.AssertEqual(t, gtvasmt("", "ptr").(*int), nil)
|
tst.AssertEqual(t, gtvasmt("", "ptr").(*int), nil)
|
||||||
|
Reference in New Issue
Block a user