1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

doc: update doc and example for validator

This commit is contained in:
dudaodong
2023-04-06 10:46:31 +08:00
parent c53d541a6b
commit 18f01ffd75
6 changed files with 316 additions and 86 deletions

View File

@@ -112,7 +112,7 @@ func ContainLetter(str string) bool {
}
// IsJSON checks if the string is valid JSON.
// Play: https://go.dev/play/p/sRS6c4K8jGk
// Play: https://go.dev/play/p/8Kip1Itjiil
func IsJSON(str string) bool {
var js json.RawMessage
return json.Unmarshal([]byte(str), &js) == nil
@@ -370,7 +370,7 @@ func IsGBK(data []byte) bool {
return true
}
// IsNumberStr check if the value is Number(integer, float) or not.
// IsNumberStr check if the value is number(integer, float) or not.
// Play: todo
func IsNumber(v any) bool {
return IsInt(v) || IsFloat(v)

View File

@@ -285,8 +285,8 @@ func ExampleIsIntStr() {
func ExampleIsJSON() {
result1 := IsJSON("{}")
result2 := IsJSON("{\"name\": \"test\"}")
result3 := IsIntStr("")
result4 := IsIntStr("abc")
result3 := IsJSON("")
result4 := IsJSON("abc")
fmt.Println(result1)
fmt.Println(result2)