Commit Graph

90 Commits

Author SHA1 Message Date
c600f3aae8 feat(container): Add NewXXXWithChecker function for gmap/gset/gtree (#4610)
为了解决开发者需要通过`var`在代码顶部创建`gmap/gset/gtree`时需要同时设置`nilchecker`的需求,为这几个容易增加带有`checker`入参的构造函数`NewxxxxWithChecker`和`NewxxxWithCheckerFrom`

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-15 14:26:42 +08:00
13524a36bc fix(container): Add NilChecker Support to gmap, gset, and gtree for Typed Nil Issue Resolution (#4605)
## 描述
本PR为`gmap`、`gset`和`gtree`容器引入了`NilChecker`机制,以解决Go语言中的`typed
nil`问题。该实现允许用户注册自定义的nil检查函数来确定值是否应被视为nil,这对于处理那些会被存储到容器中的`typed
nil`值特别有用。
## 情况描述
当前`gmap`等容器的泛型容器存在对`value`的`nil`值无法正确过滤的问题,例如以下例子中如果使用默认的`if any(value)
!=
nil`去判断就会得到错误的结果,原因是会出现带有类型的`(*Student)(nil)`直接和`nil`比较或者使用`any`强转都是不对的,使用反射可以解决但是性能太差了,所以换个思虑我们让用户自己决定如何判断`nil`就能解决这个问题
```golang
func main() {
	type Student struct {
		Name string
		Age  int
	}
	m1 := gmap.NewKVMap[int, *Student](true)
	for i := 0; i < 10; i++ {
		m1.GetOrSetFuncLock(i, func() *Student {
			if i%2 == 0 {
				return &Student{}
			}
			return nil
		})
	}
	fmt.Println(m1.Size()) //  10
	m2 := gmap.NewKVMap[int, *Student](true)
	m2.RegisterNilChecker(func(student *Student) bool {
		return student == nil
	})
	for i := 0; i < 10; i++ {
		m2.GetOrSetFuncLock(i, func() *Student {
			if i%2 == 0 {
				return &Student{}
			}
			return nil
		})
	}
	fmt.Println(m2.Size())  // 5

}

```

## 变更内容
- 在gmap、gset和gtree包中添加了`NilChecker`类型定义
- 扩展容器结构体,增加`nilChecker`字段来存储自定义nil检查函数
- 实现了`RegisterNilChecker`方法,允许用户注册自定义nil检查逻辑
- 添加了`isNil`内部方法,优先使用自定义nil检查函数或回退到默认的`any(v) == nil`检查
- 更新关键操作(AddIfNotExist、Set等)以利用nil检查机制
- 为所有三个容器类型添加了全面的测试用例以验证nilchecker功能

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-15 10:18:05 +08:00
777d7aabb5 feat(container/gtree): add generic tree feature (#4522)
add generic tree feature
improve gmap.TreeMap

---------

Co-authored-by: hailaz <739476267@qq.com>
2025-11-29 21:09:43 +08:00
5a67aac85d feat(container/gmap): add generic list map feature (#4520)
add the generic list map: ListKVMap[K,V] and let ListMap base on it.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: hailaz <739476267@qq.com>
2025-11-29 20:57:41 +08:00
132a5ab9a3 feat(container/gmap): add generic map feature (#4484)
add hash kvmap and let other hash map base on it.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: hailaz <739476267@qq.com>
2025-11-28 21:41:30 +08:00
1b26013a66 fix: update copyright notice in multiple files to specify correct file reference (#4518)
修复注释
2025-11-21 14:12:56 +08:00
94cc233325 fix: disable specific staticcheck rules and update lint config (#4396)
fix: disable specific staticcheck rules and update lint config

- Disabled staticcheck rules SA1029, SA1019, S1000, and related checks
in `.golangci.yml` to filter out unwanted linter errors.
- Updated staticcheck checks list for more precise linting control.
- Clarified configuration for easier maintenance and future updates.

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: hailaz <739476267@qq.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-08-29 10:32:30 +08:00
ee24da4e72 refactor: interface{} to any and reflect.Ptr to reflect.Pointer (#4395)
This pull request standardizes the use of the Go 1.18+ `any` type alias
instead of `interface{}` throughout the codebase. The change improves
code readability and aligns with modern Go best practices. The update
touches many files, including core data structures, code generation
templates, logging utilities, and test data, ensuring consistency across
all usages.

**Type alias migration to `any`:**

* Replaced all instances of `interface{}` with `any` in core data
structures such as `garray` and in generated model structs (e.g.,
`TableUser`, `User1`, `User2`) to modernize type usage.
[[1]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L31-R31)
[[2]](diffhunk://#diff-6c19859cb32c7516ea95ddc8f8235460818eb2f24d2204308e0d9e1b19e7d90fL15-R19)
[[3]](diffhunk://#diff-a15ba2f5e830b4833c47b902515a4f9e5a4f83a3707698f3229b307ec3776b41L15-R18)
[[4]](diffhunk://#diff-52e0837e84d49221d1b810d88fdf78221f36cffcd664fb42f8aba49a79b974dcL15-R19)
[[5]](diffhunk://#diff-11c3457d1a23a4ca6ecd00d6b856289774936b6a708384cf03aff164044e7546L15-R19)
[[6]](diffhunk://#diff-2cff9cf8e6a0cc34087326d8c8149c3bbaf74c76fdbdf5a73daed13cc04249e1L15-R19)
* Updated function signatures, method parameters, and return types from
`interface{}` to `any` in various parts of the codebase, including code
generation, service logic, and logging utilities (e.g., `mlog`).
[[1]](diffhunk://#diff-175edfeea54490b8fe4e18ffcbea5835efaf8f0b8acf623359073987cae7eb76L48-R55)
[[2]](diffhunk://#diff-2b1953fb78cf3593d8c2c7d911e95b65fd0b847c30ed0b4d167d16fe6d781235L54-R74)
[[3]](diffhunk://#diff-e001b7a4b63603b9b14f00de78a4d570bb76c5f57d856a24643f071032e12356L66-R73)
[[4]](diffhunk://#diff-5582954e8a9983988dc8854ad82067fb2ac6269b988e07357ad8db1dfec5f1a0L39-R41)
[[5]](diffhunk://#diff-c5d51d56f487779a2b6207c7ad26c7a20bbadcc846ce094fe60ab4cabff58c51L107-R107)
[[6]](diffhunk://#diff-f96e6a9fdb416eb1804ceaba1fe0ac637bff22c43837f8bb849c2366ce72d4a1L116-R121)
[[7]](diffhunk://#diff-f94c83a1b08ae060d9346f4a6031fc4a7b9a0b894e02d9afaa09018b6598eac0L112-R112)
[[8]](diffhunk://#diff-748b11dbe8828dd4c040ec23cae0b8fe57ecf0a2d1b7694ea39102294e633c64L36-R36)
[[9]](diffhunk://#diff-748b11dbe8828dd4c040ec23cae0b8fe57ecf0a2d1b7694ea39102294e633c64L74-R74)
[[10]](diffhunk://#diff-748b11dbe8828dd4c040ec23cae0b8fe57ecf0a2d1b7694ea39102294e633c64L96-R96)

**Generated code and templates:**

* Adjusted generated files and code generation templates to output `any`
instead of `interface{}` for relevant struct fields and function
signatures, ensuring that new code generation aligns with the updated
convention.
[[1]](diffhunk://#diff-6c19859cb32c7516ea95ddc8f8235460818eb2f24d2204308e0d9e1b19e7d90fL15-R19)
[[2]](diffhunk://#diff-a15ba2f5e830b4833c47b902515a4f9e5a4f83a3707698f3229b307ec3776b41L15-R18)
[[3]](diffhunk://#diff-52e0837e84d49221d1b810d88fdf78221f36cffcd664fb42f8aba49a79b974dcL15-R19)
[[4]](diffhunk://#diff-11c3457d1a23a4ca6ecd00d6b856289774936b6a708384cf03aff164044e7546L15-R19)
[[5]](diffhunk://#diff-2cff9cf8e6a0cc34087326d8c8149c3bbaf74c76fdbdf5a73daed13cc04249e1L15-R19)
[[6]](diffhunk://#diff-175edfeea54490b8fe4e18ffcbea5835efaf8f0b8acf623359073987cae7eb76L48-R55)
[[7]](diffhunk://#diff-e001b7a4b63603b9b14f00de78a4d570bb76c5f57d856a24643f071032e12356L66-R73)
[[8]](diffhunk://#diff-5582954e8a9983988dc8854ad82067fb2ac6269b988e07357ad8db1dfec5f1a0L39-R41)

**Container and utility updates:**

* Refactored the `garray` container implementation and related
constructors/methods to use `[]any` instead of `[]interface{}`, along
with corresponding function signatures.
[[1]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L31-R31)
[[2]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L52-R52)
[[3]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L62-R62)
[[4]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L73-R86)
[[5]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L96-R97)
[[6]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L107-R114)
[[7]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L124-R124)
[[8]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L135-R143)
[[9]](diffhunk://#diff-3a1259e160a4dfa5fe49dfe739fbdb986c0d0a2220a709882ea48d3ae1b8f911L167-R167)

These changes collectively modernize the codebase and prepare it for
future Go developments by using the idiomatic `any` type.
2025-08-28 16:53:19 +08:00
7ffdff37e4 chore: upgrade golangci-lint configuration and optimize codebase (#4236)
This PR includes the following changes:

- **Upgrade `.golangci.yml`**: Updated the configuration file to align
with the latest golangci-lint version, ensuring compatibility and
leveraging new features.
- **Refactor GitHub Action workflow**: Modified `golangci-lint.yml` in
the GitHub Actions workflow to reflect the updated configuration and
improve CI performance.
- **Codebase optimization**: Refactored code to address issues and
warnings raised by the updated golangci-lint rules, including:
  - Improved function length and complexity.
  - Enhanced error handling and variable naming conventions.
- Fixed minor issues such as unused imports and formatting
inconsistencies.

These changes aim to maintain code quality, ensure compatibility with
the latest tools, and improve overall maintainability.
2025-08-22 13:29:09 +08:00
b0b84a3937 ci(gci/import): improve golangci.yml and add gci linter (#4010) 2024-12-07 14:17:33 +08:00
1b23bf495a container/gmap&gset: fix deadlock when removing values during iterating (#3572) 2024-05-21 22:07:28 +08:00
b9e2b05f04 change interface ConvertDataForRecord to ConvertValueForField for package gdb (#2916) 2023-09-04 21:23:54 +08:00
4ad508c04d feat: add Diff feature to gmap (#2774) 2023-07-20 20:07:43 +08:00
1cd1449085 add package contrib/rpc/grpcx (#2169) 2023-03-08 14:12:51 +08:00
1793bf0863 add golangci feature to guarantee codes quality (#2229) 2022-11-01 20:12:21 +08:00
141ca62c6d feature/v2.2.0 (#2154) 2022-09-26 22:11:13 +08:00
1acc1b8230 improve DeepCopy feature for bunch of components, especially the container and gtime (#1956) 2022-06-29 14:58:27 +08:00
3ae23df4b3 Improve the code coverage of the gmap module (#1910) 2022-06-20 19:05:47 +08:00
0d7e28ee75 add deep copy feature 2022-05-23 16:51:10 +08:00
f2e1f63396 fix issue #1679 2022-03-21 22:04:15 +08:00
546b6b1724 t.Assert(err, nil) -> t.AssertNil(err) 2022-03-10 11:36:40 +08:00
c2fb7ada0a improve example for package gmap 2022-03-08 20:25:34 +08:00
d0a8e60ace improve example for package gmap 2022-03-08 20:14:38 +08:00
10ed04cdb8 example updates for package gmap 2022-03-08 09:49:33 +08:00
e09704a408 example updates for package gmap 2022-03-07 22:10:34 +08:00
8a27463e44 ensure sequence for json.Marshal for gmap.ListMap/TreeMap 2022-03-07 17:39:41 +08:00
3bbbe1db9c change pointer receiver that implements interface MarshalJSON to struct receiver for all packages 2022-01-19 16:55:57 +08:00
7e3d7b3575 modify UnmarshalValue Sample 2021-11-22 23:11:40 +08:00
a3dfebffb4 output modify 2021-11-22 00:26:34 +08:00
b58c5311d0 Implemented TreeMap Example 2021-11-21 12:44:59 +08:00
8ea4b71e7a Implemented ListMap Example 2021-11-20 21:46:20 +08:00
3e5b3a6dad Implemented StrStrMap Example 2021-11-20 12:37:09 +08:00
61bc38fff6 Implemented StrStrMap Example 2021-11-20 12:27:01 +08:00
7d75f6e7c5 Implemented StrStrMap Example 2021-11-20 12:13:05 +08:00
a99cc34243 Implemented StrStrMap Example 2021-11-20 12:12:32 +08:00
1db2c31ecc Implemented StrIntMap Example 2021-11-20 08:47:44 +08:00
49edad0216 Implemented StrAnyMap Example 2021-11-20 08:13:10 +08:00
51fd87bc01 Implemented StrAnyMap Example 2021-11-20 07:49:56 +08:00
9aeac45198 Implemented IntIntMap Example 2021-11-19 21:46:11 +08:00
076b15d71f Implemented IntAnyMap Example 2021-11-19 07:27:19 +08:00
7d6c9244cf Implemented AnyAnyMap Example Function:
1.Replace 2.LockFunc 3.RLockFunc 4.Flip 5.Merge 6.String 7.MarshalJSON 8.UnmarshalJSON 9.UnmarshalValue
2021-11-18 21:37:27 +08:00
3f4dff462d Merge branch 'master' of https://github.com/gogf/gf 2021-11-18 07:33:29 +08:00
36927b4371 Implemented AnyAnyMap Example Function:
1.Remove 2.Removes 3.Keys 4.Values 5.Contains 6.Size 7.IsEmpty 8.Clear
2021-11-18 07:32:29 +08:00
57ccc13e0c unit testing files renaming 2021-11-17 23:20:58 +08:00
ef29ee4804 Implemented AnyAnyMap Example Function:
1.Iterator 2.Clone 3.Map 4.MapCopy 5.MapStrAny 6.FilterEmpty 7.FilterNil 8.Set 9.Sets 10.Search 11.Get 12.Pop 13.Pops 14.GetOrSet 15.GetOrSetFunc 16.GetOrSetFuncLock 17.GetVar 18.GetVarOrSet 19.GetVarOrSetFunc 20.GetVarOrSetFuncLock
2021-11-17 23:18:35 +08:00
416a5173ae 1# Complete the AnyAnyMap Example Function (Not Implemented)
2# Implemented AnyAnyMap Example Function:
1.NewAnyAnyMap 2.NewAnyAnyMapFrom
2021-11-16 07:30:14 +08:00
cc9b3a08d0 splite gmap example file. 2021-11-16 07:20:18 +08:00
4e1bbd76f9 Merge branch 'master' of https://github.com/gogf/gf 2021-11-15 23:34:43 +08:00
570814cf6e gmap example function
1.NewFrom 2.NewHashMap 3.NewHashMapFrom
2021-11-15 23:34:25 +08:00
be03b3cdda Improved import, by group improt. 2021-11-13 23:23:55 +08:00