mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +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:
1 parent
db479ef1bc
commit
a9c75b081d
3 files changed
+48
-1
No files matched your search
@@ -207,6 +207,18 @@ func IsIp(ipstr string) bool {
|
||||
return ip != nil
|
||||
}
|
||||
|
||||
// IsIpPort check if the string is ip:port.
|
||||
// Play:
|
||||
func IsIpPort(str string) bool {
|
||||
host, port, err := net.SplitHostPort(str)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
ip := net.ParseIP(host)
|
||||
return ip != nil && IsPort(port)
|
||||
}
|
||||
|
||||
// IsIpV4 check if the string is a ipv4 address.
|
||||
// Play: https://go.dev/play/p/zBGT99EjaIu
|
||||
func IsIpV4(ipstr string) bool {
|
||||
|
||||
Reference in new issue
Block a user