mirror of
https://github.com/go-i2p/i2pkeys.git
synced 2025-06-09 09:32:58 -04:00
Reduce redundant logic in validateAddressFormat
This commit is contained in:
@ -62,13 +62,11 @@ func sanitizeAddress(addr string) string {
|
|||||||
|
|
||||||
func validateAddressFormat(addr string) error {
|
func validateAddressFormat(addr string) error {
|
||||||
host, _, err := net.SplitHostPort(addr)
|
host, _, err := net.SplitHostPort(addr)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
// If SplitHostPort fails, it means addr is not in host:port format
|
// Successfully split host:port, use just the host part
|
||||||
host = addr
|
|
||||||
}
|
|
||||||
if host != "" {
|
|
||||||
addr = host
|
addr = host
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(addr) > MaxAddressLength || len(addr) < MinAddressLength {
|
if len(addr) > MaxAddressLength || len(addr) < MinAddressLength {
|
||||||
return fmt.Errorf("invalid address length: got %d, want between %d and %d",
|
return fmt.Errorf("invalid address length: got %d, want between %d and %d",
|
||||||
len(addr), MinAddressLength, MaxAddressLength)
|
len(addr), MinAddressLength, MaxAddressLength)
|
||||||
|
Reference in New Issue
Block a user