{"id":15324110,"url":"https://github.com/dxvgef/filter","last_synced_at":"2026-04-18T22:13:11.831Z","repository":{"id":57485584,"uuid":"179272278","full_name":"dxvgef/filter","owner":"dxvgef","description":"Go语言的数据过滤包，由 数据输入、格式化、校验、输出 几个部份组成。","archived":false,"fork":false,"pushed_at":"2024-11-11T00:16:22.000Z","size":263,"stargazers_count":24,"open_issues_count":0,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T19:07:06.239Z","etag":null,"topics":["filter","interceptor","validation","validator"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dxvgef.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-03T11:04:34.000Z","updated_at":"2024-11-11T00:16:26.000Z","dependencies_parsed_at":"2024-07-27T09:55:10.419Z","dependency_job_id":null,"html_url":"https://github.com/dxvgef/filter","commit_stats":{"total_commits":150,"total_committers":4,"mean_commits":37.5,"dds":"0.033333333333333326","last_synced_commit":"4fd50a8098bb6baab1549d426de66e46123ada86"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dxvgef%2Ffilter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dxvgef%2Ffilter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dxvgef%2Ffilter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dxvgef%2Ffilter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dxvgef","download_url":"https://codeload.github.com/dxvgef/filter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248943456,"owners_count":21186958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filter","interceptor","validation","validator"],"created_at":"2024-10-01T09:24:24.754Z","updated_at":"2026-04-18T22:13:11.816Z","avatar_url":"https://github.com/dxvgef.png","language":"Go","readme":"# filter\n\ngolang 处理包，由 **数据输入、格式化、校验、输出** 几个部份组成。\n\n- 采用链式写法执行每个处理函数\n- 每个处理函数都可以自定义失败消息\n- 可将多个处理函数封装成一个函数，便于复用\n- 处理结果可以自动赋值到变量\n- 支持批量处理数据\n\n## 注意：\n\n校验函数必须是字面语义上的条件成立，才算通过校验，例如：\n\n- `Is(1)`的通过条件是值等于 1\n- `IsNot(1)`的通过条件是值不等于 1\n- `Contains(\"@\")`的通过条件是值包含字符 \"@\"\n- `NotContains(\"@\")`的通过条件是值不包含字符 \"@\"\n\n请参考单元测试代码获得使用帮助，其它问题请在 Issues 里提出。\n\n## 安装\n\n\u003e github.com/dxvgef/filter/v2\n\n---\n\n## 目录\n\n- [字符串处理](#string)\n- [字符串切片处理](#stringslice)\n- [整数处理](#integer)\n- [整数切片处理](#integerslice)\n- [浮点处理](#float)\n- [浮点切片处理](#floatslice)\n- [布尔处理](#boolean)\n- [布尔切片处理](#booleanslice)\n\n## \u003cspan id=\"string\"\u003e字符串处理\u003c/span\u003e\n\n| 分类         | 函数名                  | 描述                                      |\n|------------|----------------------|-----------------------------------------|\n| **输入函数**   | `FromStr`         | 输入`string`类型                            |\n| **格式化函数**  | `ToUpper`            | 同`strings.ToUpper`                      |\n|            | `ToLower`            | 同`strings.ToLower`                      |\n|            | `Trim`               | 同`strings.Trim`                         |\n|            | `TrimSpace`          | 同`strings.TrimSpace`                    |\n|            | `TrimLeft`           | 同`strings.TrimLeft`                     |\n|            | `TrimRight`          | 同`strings.TrimRight`                    |\n|            | `TrimPrefix`         | 同`strings.Prefix`                       |\n|            | `TrimSuffix`         | 同`strings.TrimSuffix`                   |\n|            | `Replace`            | 同`strings.Replace`                      |\n|            | `ReplaceAll`         | `strings.ReplaceAll`                    |\n|            | `RemoveSpace`        | 删除所有空格                                  |\n|            | `Base64StdEncode`    | 使用 base64.StdEncoding 编码                |\n|            | `Base64StdDecode`    | 使用 base64.StdEncoding 解码                |\n|            | `Base64RawStdEncode` | 使用 base64.RawStdEncoding 编码             |\n|            | `Base64RawStdDecode` | 使用 base64.RawStdEncoding 解码             |\n|            | `Base64URLEncode`    | 使用 base64.URLEncoding 编码                |\n|            | `Base64URLDecode`    | 使用 base64.URLEncoding 解码                |\n|            | `Base64RawURLEncode` | 使用 base64.RawURLEncoding 编码             |\n|            | `Base64RawURLDecode` | 使用 base64.RawURLEncoding 解码             |\n|            | `HTMLEscape`         | 使用 html.EscapeString 编码                 |\n|            | `HTMLUnescape`       | 使用 html.UnescapeString 解码               |\n|            | `URLPathEscape`      | 使用 url.PathEscape 编码                    |\n|            | `URLPathUnescape`    | 使用 url.PathUnescape 解码                  |\n|            | `URLQueryEscape`     | 使用 url.QueryEscape 编码                   |\n|            | `URLQueryUnescape`   | 使用 url.QueryUnescape 解码                 |\n|            | `ToSnakeCase`        | 转为小写蛇形命名风格                              |\n|            | `ToCamelCase`        | 转为小写开头的驼峰命名风格                           |\n| **校验函数**   | `Is`                 | 是                                       |\n|            | `IsNot`              | 不是                                      |\n|            | `Contains`           | 包含                                      |\n|            | `NotContains`        | 没有包含                                    |\n|            | `LenIs`           | 长度是                                     |\n|            | `LenIsNot`        | 长度不是                                    |\n|            | `MinLen`          | 长度最小值                                   |\n|            | `MaxLen`          | 长度最大值                                   |\n|            | `LenRange`        | 长度范围                                    |\n|            | `UTF8LenIs`       | UTF8编码的长度是                              |\n|            | `UTF8LenIsNot`    | UTF8编码的长度不是                             |\n|            | `MinUTF8Len`      | UTF8编码的长度最小值                            |\n|            | `MaxUTF8Len`      | UTF8编码的长度最大值                            |\n|            | `UTF8LenRange`    | UTF8编码的长度范围                             |\n|            | `In`                 | 在列表中                                    |\n|            | `NotIn`              | 不在列表中                                   |\n|            | `AllowedChars`       | 允许的字符                                   |\n|            | `BlockChars`         | 不允许的字符                                  |\n|            | `AllowedSymbols`     | 允许的符号                                   |\n|            | `BlockSymbols`       | 不允许的符号                                  |\n|            | `HasLetter`          | 包含字母                                    |\n|            | `HasLower`           | 包含小写字母                                  |\n|            | `HasUpper`           | 包含大写字母                                  |\n|            | `HasNumber`          | 包含数字                                    |\n|            | `HasSymbol`          | 包含符号                                    |\n|            | `HasPrefix`          | 包含前缀                                    |\n|            | `HasSuffix`          | 包含后缀                                    |\n|            | `IsLetter`           | 是字母                                     |\n|            | `IsLower`            | 是小写字母                                   |\n|            | `IsUpper`            | 是大写字母                                   |\n|            | `IsLowerOrNumber`    | 是小写字母或数字                                |\n|            | `IsUpperOrNumber`    | 是大写字母或数字                                |\n|            | `IsLetterOrNumber`   | 是字母或数字                                  |\n|            | `IsChinese`          | 是汉字                                     |\n|            | `IsMail`             | 是电邮地址                                   |\n|            | `IsIPv4`             | 是IPv4地址                                 |\n|            | `IsIPv6`             | 是IPv6地址                                 |\n|            | `IsIP`               | 是IPv4或IPv6地址                            |\n|            | `IsTCPAddr`          | 是 IP:Port 格式                            |\n|            | `IsMAC`              | 是MAC地址                                  |\n|            | `IsJSON`             | 是JSON格式                                 |\n|            | `IsSQLObject`        | 是有效的SQL对象名                              |\n|            | `IsSQLOperator`      | 是有效的SQL运算符                              |\n|            | `IsURL`              | 是有效的URL                                 |\n|            | `IsUUID`             | 是UUID格式                                 |\n|            | `IsULID`             | 是ULID格式                                 |\n|            | `IsChineseIDCard`    | 是中国大陆地区身份证号码                            |\n|            | `IsHexColor`         | 是HEX颜色值（#前缀可选）                          |\n| **自定义函数**  | `Custom`             | 自定义函数，详见 `CustomStringFunc`             |\n| **类型转换函数** | `ToStringSlice`      | 转为`StringSliceType`类型 (string)，须指定分隔符   |\n|            | `ToInteger`          | 转为`IntegerType`类型 (int64)               |\n|            | `ToIntegerSlice`     | 转为`IntegerSliceType`类型 ([]int64)，须指定分隔符 |\n|            | `ToBoolean`          | 转为`Boolean`类型 (bool)                    |\n|            | `ToBooleanSlice`     | 转为`BooleanSliceType`类型 ([]bool)，须指定分隔符  |\n|            | `ToFloat`            | 转为`FloatType`类型 (float64)               |\n|            | `ToFloatSlice`       | 转为`FloatSliceType`类型 ([]float64)，须指定分隔符 |\n| **输出函数**   | `Error`              | 错误消息，`error`类型                          |\n|            | `Value`              | 处理后的值，`string`类型                        |\n|            | `Result`             | `Value(), Error()`                      |\n|            | `DefaultValue`       | 没有错误时返回`Value()`，否则返回指定值                |\n|            | `Set`                | 赋值到`string`类型的变量，并返回处理结果                |\n\n---\n\n## \u003cspan id=\"stringslice\"\u003e字符串切片处理\u003c/span\u003e\n\n与`StringType`函数的差异：\n\n| 分类        | 函数名               | 描述             |\n|-----------|-------------------|----------------|\n| **输入函数**  | `FromStrSlice` | 输入`[]string`类型 |\n| **格式化函数** | `DeleteEmpty`     | 删除空字符串的元素      |\n| **校验函数**  | `In`              | 在列表中           |\n|           | `NotIn`           | 没在列表中          |\n|           | `MinCount`        | 元素数量最小值        |\n|           | `MaxCount`        | 元素数量最大值        |\n|           | `CountIs`         | 元素数量等于         |\n|           | `CountIsNot`      | 元素数量不等于        |\n|           | `LenIs`        | 元素长度等于         |\n|           | `LenIsNot`     | 元素长度不等于        |\n|           | `MinLen`       | 元素长度最小值        |\n|           | `MaxLen`       | 元素长度最大值        |\n|           | `LenRange`     | 元素长度范围         |\n\n---\n\n## \u003cspan id=\"integer\"\u003e整数处理\u003c/span\u003e\n\n| 分类        | 函数名             | 描述                     |\n|-----------|-----------------|------------------------|\n| **输入函数**  | `FromInt`   | 输入`int64`类型            |\n| **格式化函数** | `Replace`       | 替换                     |\n| **校验函数**  | `Is`            | 等于                     |\n|           | `IsNot`         | 不等于                    |\n|           | `Min`           | 最小值                    |\n|           | `Max`           | 最大值                    |\n|           | `Range`         | 范围                     |\n|           | `In`            | 在列表中                   |\n|           | `NotIn`         | 不在列表中                  |\n| **自定义函数** | `Custom`        | 详见 `CustomIntegerFunc` |\n| **输出函数**  | `Error`         | 错误消息，`error`类型         |\n|           | `Value`         | 处理后的值，`int64`类型        |\n|           | `Result`        | `Value(), Error()`     |\n|           | `Set`           | 赋值到整数类型的变量，并返回处理结果     |\n|           | `Int`           | 转为`int`类型              |\n|           | `DefaultInt`    | 转为`int`类型，失败返回指定的值     |\n|           | `Int8`          | 转为`int8`类型             |\n|           | `DefaultInt8`   | 转为`int8`类型，失败返回指定的值    |\n|           | `Int16`         | 转为`int16`类型            |\n|           | `DefaultInt16`  | 转为`int16`类型，失败返回指定的值   |\n|           | `Int32`         | 转为`int32`类型            |\n|           | `DefaultInt32`  | 转为`int32`类型，失败返回指定的值   |\n|           | `Int64`         | 转为`int64`类型            |\n|           | `DefaultInt64`  | 转为`int64`类型，失败返回指定的值   |\n|           | `Uint`          | 转为`uint`类型             |\n|           | `DefaultUint`   | 转为`uint`类型，失败返回指定的值    |\n|           | `Uint8`         | 转为`uint8`类型            |\n|           | `DefaultUint8`  | 转为`uint8`类型，失败返回指定的值   |\n|           | `Uint16`        | 转为`uint16`类型           |\n|           | `DefaultUint16` | 转为`uint16`类型，失败返回指定的值  |\n|           | `Uint32`        | 转为`uint32`类型           |\n|           | `DefaultUint32` | 转为`uint32`类型，失败返回指定的值  |\n|           | `Uint64`        | 转为`uint64`类型           |\n|           | `DefaultUint64` | 转为`uint64`类型，失败返回指定的值  |\n\n---\n\n## \u003cspan id=\"integerslice\"\u003e整数切片处理\u003c/span\u003e\n\n与`IntegerType`类型的差异\n\n| 分类        | 函数名                  | 描述                                     |\n|-----------|----------------------|----------------------------------------|\n| **输入函数**  | `FromIntSlice`   | 输入`[]int64`类型                          |\n| **校验函数**  | `MinCount`           | 元素数量最小值                                |\n|           | `MaxCount`           | 元素数量最大值                                |\n|           | `CountIs`            | 元素数量等于                                 |\n|           | `CountIsNot`         | 元素数量不等于                                |\n| **输出函数**  | `IntSlice`           | 转为`[]int`类型                            |\n|           | `DefaultIntSlice`    | 转为`[]int`类型，失败返回指定的值                   |\n|           | `Int8Slice`          | 转为`[]int8`类型                           |\n|           | `DefaultInt8Slice`   | 转为`[]int8`类型，失败返回指定的值                  |\n|           | `Int16Slice`         | 转为`[]int16`类型                          |\n|           | `DefaultInt16Slice`  | 转为`[]int16`类型，失败返回指定的值                 |\n|           | `Int32Slice`         | 转为`[]int32`类型                          |\n|           | `DefaultInt32Slice`  | 转为`[]int32`类型，失败返回指定的值                 |\n|           | `Int64Slice`         | 转为`[]int64`类型                          |\n|           | `DefaultInt64Slice`  | 转为`[]int64`类型，失败返回指定的值                 |\n|           | `UintSlice`          | 转为`[]uint`类型                           |\n|           | `DefaultUintSlice`   | 转为`[]uint`类型，失败返回指定的值                  |\n|           | `Uint8Slice`         | 转为`[]uint8`类型                          |\n|           | `DefaultUint8Slice`  | 转为`[]uint8`类型，失败返回指定的值                 |\n|           | `Uint16Slice`        | 转为`[]uint16`类型                         |\n|           | `DefaultUint16Slice` | 转为`[]uint16`类型，失败返回指定的值                |\n|           | `Uint32Slice`        | 转为`[]uint32`类型                         |\n|           | `DefaultUint32Slice` | 转为`[]uint32`类型，失败返回指定的值                |\n|           | `Uint64Slice`        | 转为`[]uint64`类型                         |\n|           | `DefaultUint64Slice` | 转为`[]uint64`类型，失败返回指定的值                |\n\n---\n\n## \u003cspan id=\"float\"\u003e浮点值处理\u003c/span\u003e\n\n| 分类        | 函数名              | 描述                              |\n|-----------|------------------|---------------------------------|\n| **输入函数**  | `FromFloat`      | 输入`float64`类型                   |\n| **校验函数**  | `Is`             | 等于                              |\n|           | `IsNot`          | 不等于                             |\n|           | `Min`            | 最小值                             |\n|           | `Max`            | 最大值                             |\n|           | `Range`          | 范围                              |\n|           | `In`             | 在列表中                            |\n|           | `NotIn`          | 不在列表中                           |\n| **自定义函数** | `Custom`         | 自定义浮点值处理函数，详见 `CustomFloatFunc` |\n| **输出函数**  | `Error`          | 错误消息，`error`类型                  |\n|           | `Value`          | 处理后的值，`float64`类型               |\n|           | `Result`         | `Value(), Error()`              |\n|           | `Set`            | 赋值到浮点类型的变量，并返回处理结果              |\n|           | `Float32`        | 转为`float32`类型                   |\n|           | `DefaultFloat32` | 转为`float32`类型，失败返回指定的值          |\n|           | `Float64`        | 转为`float64`类型                   |\n|           | `DefaultFloat64` | 转为`float64`类型，失败返回指定的值          |\n\n---\n\n## \u003cspan id=\"floatslice\"\u003e浮点切片处理\u003c/span\u003e\n\n与`FloatType`类型的差异\n\n| 分类       | 函数名                   | 描述                       |\n|----------|-----------------------|--------------------------|\n| **输入函数** | `FromFloatSlice`      | 输入`[]float64`类型          |\n| **校验函数** | `MinCount`            | 元素数量最小值                  |\n|          | `MaxCount`            | 元素数量最大值                  |\n|          | `CountIs`             | 元素数量等于                   |\n|          | `CountIsNot`          | 元素数量不等于                  |\n| **输出函数** | `Float32Slice`        | 转为`[]float32`类型          |\n|          | `DefaultFloat32Slice` | 转为`[]float32`类型，失败返回指定的值 |\n|          | `Float64Slice`        | 转为`[]float64`类型          |\n|          | `DefaultFloat64Slice` | 转为`[]float64`类型，失败返回指定的值 |\n\n---\n\n## \u003cspan id=\"boolean\"\u003e布尔值处理\u003c/span\u003e\n\n| 分类        | 函数名            | 描述                           |\n|-----------|----------------|------------------------------|\n| **输入函数**  | `FromBool`  | 输入`bool`类型                   |\n| **校验函数**  | `Is`           | 等于                           |\n|           | `IsNot`        | 不等于                          |\n| **自定义函数** | `Custom`       | 自定义函数，详见 `CustomBooleanFunc` |\n| **输出函数**  | `Error`        | 错误消息，`error`类型               |\n|           | `Value`        | 处理后的值，`bool`类型               |\n|           | `Result`       | `Value(), Error()`           |\n|           | `DefaultValue` | 没有错误时返回`Value()`，否则返回指定值     |\n|           | `Set`          | 赋值到`bool`类型的变量，并返回处理结果       |\n\n---\n\n## \u003cspan id=\"booleanslice\"\u003e布尔切片处理\u003c/span\u003e\n\n与`BooleanType`类型的差异\n\n| 分类       | 函数名                | 描述           |\n|----------|--------------------|--------------|\n| **输入函数** | `FromBoolSlice` | 输入`[]bool`类型 |\n| **校验函数** | `CountIs`          | 元素数量等于       |\n|          | `CountIsNot`       | 元素数量不等于      |\n|          | `MinCount`         | 元素数量最小值      |\n|          | `MaxCount`         | 元素数量最大值      |\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdxvgef%2Ffilter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdxvgef%2Ffilter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdxvgef%2Ffilter/lists"}