Skip to content

Commit

Permalink
minor internal code reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
gaissmai committed Jul 29, 2022
1 parent ee4a305 commit b019088
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions iprange.go
Expand Up @@ -84,28 +84,15 @@ func FromString(s string) (IPRange, error) {
return zeroValue, err
}

if first.Zone() != "" || last.Zone() != "" {
return zeroValue, errors.New("ip address MUST NOT have a zone")
}

if first.Is4() && !last.Is4() || first.Is6() && !last.Is6() {
return zeroValue, errors.New("first and last address have different IP versions")
}
if last.Less(first) {
return zeroValue, errors.New("last address is less than first address")
}
return IPRange{first, last}, nil
return FromAddrs(first, last)
}

// an addr, or maybe just rubbish
addr, err := netip.ParseAddr(s)
if err != nil {
return zeroValue, err
}
if addr.Zone() != "" {
return zeroValue, errors.New("ip address MUST NOT have a zone")
}
return IPRange{addr, addr}, nil
return FromAddrs(addr, addr)
}

// FromPrefix returns an IPRange from the standard library's netip.Prefix type.
Expand Down

0 comments on commit b019088

Please sign in to comment.