refactor(container): add default nil checker, rename RegisterNilChecker to SetNilChecker, migrate instance containers to type-safe generics#4630
Merged
gqcn merged 17 commits intogogf:masterfrom Jan 23, 2026
Conversation
- 修改 RegisterNilChecker 方法返回实例以支持链式调用 - 更新 Core 结构体中 links 字段类型为类型安全的 KVMap - 添加专门的链接检查器函数用于连接池管理 - 使用泛型 KVMap 替代原始 map 类型提升类型安全性 - 简化连接关闭逻辑并移除不必要的类型断言 - 优化统计功能中的迭代器实现提高性能
- 将 jsonMap 从 StrAnyMap 类型更改为泛型 KVMap[string, *gjson.Json] 类型 - 添加 jsonMapChecker 函数用于 JSON 对象验证 - 使用 NewKVMapWithChecker 替代 NewStrAnyMap 提高类型安全性 - 修改 GetOrSetFuncLock 回调函数返回类型为 *gjson.Json - 简化数据库链接关闭日志中的键值转换逻辑
- 将 dm 驱动中的 conflictKeySet 从 gset.New 修改为 gset.NewStrSet - 将 gaussdb 驱动中的 conflictKeySet 从 gset.New 修改为 gset.NewStrSet - 将 mssql 驱动中的 conflictKeySet 从 gset.New 修改为 gset.NewStrSet - 将 oracle 驱动中的 conflictKeySet 从 gset.New 修改为 gset.NewStrSet - 统一使用字符串集合类型以提高类型安全性
gqcn
requested changes
Jan 21, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the codebase to improve type safety by migrating from untyped containers (gmap.Map, gset.New) to type-safe generic containers (gmap.KVMap[K, V], gset.NewStrSet).
Changes:
- Migrated database connection pool management to use type-safe
KVMap[ConfigNode, *sql.DB]instead of rawmap[any]any - Updated database drivers (dm, gaussdb, mssql, oracle) to use
gset.NewStrSetfor string-only conflict key sets - Enhanced configuration file adapter to use typed
KVMap[string, *gjson.Json]for JSON object storage - Modified
RegisterNilCheckermethods across container types to return receiver instances for method chaining support
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| database/gdb/gdb.go | Updated Core struct to use typed KVMap for database links and added linksChecker function |
| database/gdb/gdb_core.go | Simplified connection closing logic with typed map callback |
| database/gdb/gdb_core_stats.go | Updated iterator to use typed callback parameters |
| contrib/drivers/dm/dm_do_insert.go | Changed conflictKeySet from generic gset.New to gset.NewStrSet |
| contrib/drivers/gaussdb/gaussdb_do_insert.go | Changed conflictKeySet from generic gset.New to gset.NewStrSet |
| contrib/drivers/mssql/mssql_do_insert.go | Changed conflictKeySet from generic gset.New to gset.NewStrSet |
| contrib/drivers/oracle/oracle_do_insert.go | Changed conflictKeySet from generic gset.New to gset.NewStrSet |
| os/gcfg/gcfg_adapter_file.go | Migrated jsonMap to typed KVMap with custom nil checker |
| container/gmap/gmap_hash_k_v_map.go | Modified RegisterNilChecker to return receiver for method chaining |
| container/gmap/gmap_list_k_v_map.go | Modified RegisterNilChecker to return receiver for method chaining |
| container/gset/gset_t_set.go | Modified RegisterNilChecker to return receiver for method chaining |
| container/gtree/gtree_k_v_avltree.go | Modified RegisterNilChecker to return receiver for method chaining |
| container/gtree/gtree_k_v_btree.go | Modified RegisterNilChecker to return receiver for method chaining |
| container/gtree/gtree_k_v_redblacktree.go | Modified RegisterNilChecker to return receiver for method chaining |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
|
这个PR先hang一段时间,感觉这个泛型版本的 |
Member
Author
emmm其实之前已经改过一批合进去了 |
…fix/generic-container-nil-checker
…f into fix/generic-container-nil-checker
fix(container): add default nil checker, rename RegisterNilChecker to SetNilChecker
chore(container): comments update
heihutu
reviewed
Jan 23, 2026
gqcn
approved these changes
Jan 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更说明
本 PR 主要对代码库进行了重构,以提升类型安全性和优化连接管理实现。
详细变更
1. 数据库连接管理优化
RegisterNilChecker方法返回实例以支持链式调用,涉及KVMap、ListKVMap、TSet、AVLKVTree、BKVTree、RedBlackKVTree等多个容器类型Core结构体中links字段类型为类型安全的KVMap[ConfigNode, *sql.DB]KVMap替代原始 map 类型提升类型安全性2. 数据库驱动类型安全增强
conflictKeySet从gset.New修改为gset.NewStrSet3. 配置文件适配器类型安全改进
jsonMap从StrAnyMap类型更改为泛型KVMap[string, *gjson.Json]类型jsonMapChecker函数用于 JSON 对象验证NewKVMapWithChecker替代NewStrAnyMap提高类型安全性影响范围