|
|
de9d3c2b3c
|
feat(util/gconv): Add OmitEmpty and OmitNil options to Scan function (#4584)
## 改进内容
- 扩展 `ScanOption`/`StructOption` 结构体,添加 `OmitEmpty bool` 字段:当设置为 true
时,跳过空值(如空字符串、零值等)的赋值;添加 `OmitNil bool` 字段:当设置为 true 时,跳过 nil 值的赋值;
- 添加 `ScanWithOptions` 函数,支持通过 `ScanOption` 参数使用新选项
- 原有的 `Scan` 函数行为完全不变
- 通过 `NewConverter` 创建的转换器也支持新功能
## 使用示例
### 基本用法
```go
type User struct {
Name *string
Age int
Email string
}
type Person struct {
Name string
Age int
Email string
}
user := User{Name: nil, Age: 25, Email: ""}
person := Person{Name: "zhangsan", Age: 0, Email: "old@example.com"}
err := gconv.ScanWithOptions(user, &person, gconv.ScanOption{
OmitEmpty: true,
OmitNil: true,
})
// 结果: person.Name 保持 "zhangsan",person.Age 变为 25,person.Email 保持 "old@example.com"
```
后续可以将`func Scan(srcValue any, dstPointer any, paramKeyToAttrMap
...map[string]string) (err error)`和`func ScanWithOptions(srcValue any,
dstPointer any, option ...ScanOption) (err error)`直接用`func Scan(srcValue
any, dstPointer any, option ...ScanOption) (err
error)`代替,`ScanOption`里已经包含了`paramKeyToAttrMap map[string]string`
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
2026-01-16 10:19:02 +08:00 |
|
|
|
dfe088f5cd
|
refactor(util/gconv): add Converter feature for more flexable and extensible type converting (#4107)
|
2025-03-06 23:04:26 +08:00 |
|
|
|
a5c8b966e2
|
feat(util/gconv): add basic types conversion support for function Scan (#3991)
|
2024-12-18 10:41:09 +08:00 |
|
|
|
1b4ebc0812
|
perf(util/gconv): add cache logic to enhance performance (#3673)
|
2024-09-09 16:17:01 +08:00 |
|
|
|
607f079b23
|
fix: cache value assertion panic if the cache adapter is not in-memory for soft time feature of package gdb; improve converting performance for gconv.Scan (#3351)
|
2024-03-07 11:36:42 +08:00 |
|
|
|
ea5d52cb2f
|
fix issue #3147 (#3161)
|
2023-11-22 21:05:39 +08:00 |
|
|
|
0b407c5e6d
|
fix "gf gen pb" api and ctrl not working well. (#3076)
|
2023-11-08 21:26:51 +08:00 |
|
|
|
972f8c3aff
|
improve comments for package gconv (#3057)
|
2023-10-17 21:09:46 +08:00 |
|
|
|
1793bf0863
|
add golangci feature to guarantee codes quality (#2229)
|
2022-11-01 20:12:21 +08:00 |
|
|
|
6aa5c2b2ef
|
Fix/1748 issues #1748 (#1817)
|
2022-05-23 22:09:11 +08:00 |
|
|
|
b27259aded
|
fix issue converting empty map[string]string to map[string]interface{}
|
2021-12-17 17:22:55 +08:00 |
|
|
|
7b22355abb
|
expose package internal/structs as os/gstructs; add package gtag for custom tag storage feature
|
2021-11-24 16:17:50 +08:00 |
|
|
|
d864120353
|
Improved import, by group improt.
|
2021-11-13 23:30:31 +08:00 |
|
|
|
42c4b32720
|
add gconv.ScanList
|
2021-11-07 00:16:14 +08:00 |
|
|
|
4acc0e9876
|
gconv.ScanList
|
2021-11-05 01:15:11 +08:00 |
|
|
|
1bc0635f8b
|
version 2
|
2021-10-11 21:41:56 +08:00 |
|
|
|
337c2d0953
|
filter issue in internal/structs
|
2021-10-06 11:10:35 +08:00 |
|
|
|
71189c8fb0
|
improve converting performance for equal type converting
|
2021-10-03 00:58:57 +08:00 |
|
|
|
993bf897cf
|
remove deprecated functions; refract package gjson
|
2021-09-27 22:47:39 +08:00 |
|
|
|
abc8e62d58
|
add package gcode and improve error implements for package gerror
|
2021-08-24 21:18:59 +08:00 |
|
|
|
f03f56ba4e
|
improve gconv.Struct for map attribute converting
|
2021-08-19 11:28:25 +08:00 |
|
|
|
ad6c4f5245
|
improve session storage for package gsession
|
2021-08-16 21:47:45 +08:00 |
|
|
|
0ddacdd7e2
|
add error code for components
|
2021-07-20 23:02:02 +08:00 |
|
|
|
50ffaef33f
|
add context for intlog/gsession;improve struct/structs converting for package gconv
|
2021-06-26 16:23:54 +08:00 |
|
|
|
482e093331
|
add map/[]map converting support for gconv.Scan;improve gconv.MaptoMaps
|
2021-03-23 17:53:20 +08:00 |
|
|
|
093034acd1
|
copyright comment update
|
2021-01-17 21:46:25 +08:00 |
|
|
|
9f04e46166
|
mark gconv.StructDeep/StructsDeep deprecated
|
2020-11-05 23:02:29 +08:00 |
|
|
|
c135122ca1
|
improve package gconv for detailed handling of interface attributes
|
2020-07-13 23:13:50 +08:00 |
|
|
|
508cb7db88
|
add and improve Scan/ScanDeep feature for package gdb/gvar/gjson/gconv
|
2020-06-15 16:46:48 +08:00 |
|