Prem Chaitanya Prathi bc06867cc9
chore: utils tests (#661)
* chore: add tests for utils

* chore:delete unused code

* fix: ipv6 validation issue
2023-08-22 19:18:43 +05:30

19 lines
340 B
Go

package utils
import (
"net"
"strings"
)
// IsIPv4 validates if string is a valid IPV4 address
func IsIPv4(str string) bool {
ip := net.ParseIP(str).To4()
return ip != nil
}
// IsIPv6 validates if string is a valid IPV6 address
func IsIPv6(str string) bool {
ip := net.ParseIP(str)
return ip != nil && strings.Contains(str, ":")
}