comment + drop var declaration + explicit zero return
This commit is contained in:
parent
dbec5b7c9c
commit
82d3ba61e4
1 changed files with 7 additions and 10 deletions
|
@ -49,20 +49,17 @@ func LastAddress(n *net.IPNet) net.IP {
|
||||||
ip[3]|^n.Mask[3])
|
ip[3]|^n.Mask[3])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetIpsFromIpRange takes a CIDR range and returns the start and end IP
|
||||||
func GetIpsFromIpRange(host string) (int64, int64, error) {
|
func GetIpsFromIpRange(host string) (int64, int64, error) {
|
||||||
var ipStart int64
|
_, parsedRange, err := net.ParseCIDR(host)
|
||||||
var ipEnd int64
|
if err != nil {
|
||||||
var err error
|
return 0, 0, fmt.Errorf("'%s' is not a valid CIDR", host)
|
||||||
var parsedRange *net.IPNet
|
|
||||||
|
|
||||||
if _, parsedRange, err = net.ParseCIDR(host); err != nil {
|
|
||||||
return ipStart, ipEnd, fmt.Errorf("'%s' is not a valid CIDR", host)
|
|
||||||
}
|
}
|
||||||
if parsedRange == nil {
|
if parsedRange == nil {
|
||||||
return ipStart, ipEnd, fmt.Errorf("unable to parse network : %s", err)
|
return 0, 0, fmt.Errorf("unable to parse network : %s", err)
|
||||||
}
|
}
|
||||||
ipStart = int64(IP2Int(parsedRange.IP))
|
ipStart := int64(IP2Int(parsedRange.IP))
|
||||||
ipEnd = int64(IP2Int(LastAddress(parsedRange)))
|
ipEnd := int64(IP2Int(LastAddress(parsedRange)))
|
||||||
|
|
||||||
return ipStart, ipEnd, nil
|
return ipStart, ipEnd, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue