mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-09 23:22:28 +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:
@@ -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