1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-08 14:42:27 +08:00

feat(validator): add IsIpPort (#294)

* fix: json tag omitempty convert error

* feat(validator): add IsIpPort

- Add IsIpPort function to check if a string is in the format ip:port
- Update validator_test.go to include tests for the new IsIpPort function
- Add an example test for IsIpPort in validator_example_test.go
This commit is contained in:
chentong
2025-02-17 10:03:15 +08:00
committed by GitHub
parent db479ef1bc
commit a9c75b081d
3 changed files with 48 additions and 1 deletions

View File

@@ -348,6 +348,24 @@ func ExampleIsIp() {
// false
}
func ExampleIsIpPort() {
result1 := IsIpPort("127.0.0.1:8080")
result2 := IsIpPort("[0:0:0:0:0:0:0:1]:8080")
result3 := IsIpPort(":8080")
result4 := IsIpPort("::0:0:0:0:")
fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
// Output:
// true
// true
// false
// false
}
func ExampleIsIpV4() {
result1 := IsIpV4("127.0.0.1")
result2 := IsIpV4("::0:0:0:0:0:0:1")