From 063df0f0d1063f01b2c43f41ded3bc5811b69bcd Mon Sep 17 00:00:00 2001 From: dudaodong Date: Sat, 27 Aug 2022 19:04:57 +0800 Subject: [PATCH] doc: add docment for IsZeroValue function --- README.md | 1 + README_zh-CN.md | 1 + docs/validator.md | 33 ++++++++++++++++++++++++++++++++- docs/validator_zh-CN.md | 24 ++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 168ab0e..07ca8df 100644 --- a/README.md +++ b/README.md @@ -493,6 +493,7 @@ import "github.com/duke-git/lancet/v2/validator" - [IsStrongPassword](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsStrongPassword) - [IsUrl](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsUrl) - [IsWeakPassword](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsWeakPassword) +- [IsZeroValue](https://github.com/duke-git/lancet/blob/main/docs/validator.md#IsZeroValue) ### 19. xerror package implements helpers for errors. ```go diff --git a/README_zh-CN.md b/README_zh-CN.md index 64c1f85..cf0d06e 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -490,6 +490,7 @@ import "github.com/duke-git/lancet/v2/validator" - [IsStrongPassword](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsStrongPassword) - [IsUrl](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsUrl) - [IsWeakPassword](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsWeakPassword) +- [IsZeroValue](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsZeroValue) ### 19. xerror包实现一些错误处理函数 diff --git a/docs/validator.md b/docs/validator.md index 07e82ec..e11f544 100644 --- a/docs/validator.md +++ b/docs/validator.md @@ -47,6 +47,7 @@ import ( - [IsStrongPassword](#IsStrongPassword) - [IsUrl](#IsUrl) - [IsWeakPassword](#IsWeakPassword) +- [IsZeroValue](#IsZeroValue)
@@ -765,7 +766,7 @@ func main() { ### IsWeakPassword -

Check if the string is weak password(only letter or only number or letter + number) +

Checks if the string is weak password(only letter or only number or letter + number) .

Signature: @@ -792,6 +793,36 @@ func main() { +### IsZeroValue +

Checks if passed value is a zero value.

+ +Signature: + +```go +func IsZeroValue(value any) bool +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/v2/validator" +) + +func main() { + fmt.Println(validator.IsZeroValue(nil)) //true + fmt.Println(validator.IsZeroValue(0)) //true + fmt.Println(validator.IsZeroValue("")) //true + fmt.Println(validator.IsZeroValue([]int)) //true + fmt.Println(validator.IsZeroValue(interface{})) //true + + fmt.Println(validator.IsZeroValue("0")) //false + fmt.Println(validator.IsZeroValue("nil")) //false +} +``` + + + diff --git a/docs/validator_zh-CN.md b/docs/validator_zh-CN.md index fc19381..67b7a04 100644 --- a/docs/validator_zh-CN.md +++ b/docs/validator_zh-CN.md @@ -47,6 +47,7 @@ import ( - [IsStrongPassword](#IsStrongPassword) - [IsUrl](#IsUrl) - [IsWeakPassword](#IsWeakPassword) +- [IsZeroValue](#IsZeroValue)
@@ -792,8 +793,31 @@ func main() { +### IsZeroValue +

判断传入的参数值是否为零值

+函数签名: +```go +func IsZeroValue(value any) bool +``` +例子: +```go +import ( + "fmt" + "github.com/duke-git/lancet/v2/validator" +) +func main() { + fmt.Println(validator.IsZeroValue(nil)) //true + fmt.Println(validator.IsZeroValue(0)) //true + fmt.Println(validator.IsZeroValue("")) //true + fmt.Println(validator.IsZeroValue([]int)) //true + fmt.Println(validator.IsZeroValue(interface{})) //true + + fmt.Println(validator.IsZeroValue("0")) //false + fmt.Println(validator.IsZeroValue("nil")) //false +} +```