Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:(util/gconv): 把转换相关的配置独立出来 #4114

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
修改reflect.TypeFor的实现
wln32 committed Jan 13, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit ead979c87df6912b89a2f5cb02802d0c7e833393
16 changes: 10 additions & 6 deletions database/gdb/gdb_convert_config.go
Original file line number Diff line number Diff line change
@@ -20,16 +20,20 @@ var (
convertConfig = gconv.NewConvertConfig("gf.orm")
)

func reflectTypeFor[T any]() reflect.Type {
return reflect.TypeOf((*T)(nil)).Elem()
}

func init() {
convertConfig.RegisterDefaultConvertFuncs()

convertConfig.RegisterTypeConvertFunc(reflect.TypeFor[[]string](), convertToSliceFunc)
convertConfig.RegisterTypeConvertFunc(reflect.TypeFor[[]float32](), convertToSliceFunc)
convertConfig.RegisterTypeConvertFunc(reflect.TypeFor[[]float32](), convertToSliceFunc)
convertConfig.RegisterTypeConvertFunc(reflect.TypeFor[[]int64](), convertToSliceFunc)
convertConfig.RegisterTypeConvertFunc(reflect.TypeFor[map[string]any](), convertToSliceFunc)
convertConfig.RegisterTypeConvertFunc(reflectTypeFor[[]string](), convertToSliceFunc)
convertConfig.RegisterTypeConvertFunc(reflectTypeFor[[]float32](), convertToSliceFunc)
convertConfig.RegisterTypeConvertFunc(reflectTypeFor[[]float32](), convertToSliceFunc)
convertConfig.RegisterTypeConvertFunc(reflectTypeFor[[]int64](), convertToSliceFunc)
convertConfig.RegisterTypeConvertFunc(reflectTypeFor[map[string]any](), convertToSliceFunc)

convertConfig.RegisterInterfaceTypeConvertFunc(reflect.TypeFor[sql.Scanner](), sqlScanner)
convertConfig.RegisterInterfaceTypeConvertFunc(reflectTypeFor[sql.Scanner](), sqlScanner)
}

func convertToSliceFunc(from any, to reflect.Value) error {