comment + drop var declaration + explicit zero return

This commit is contained in:
marco 2024-04-29 15:43:52 +02:00
parent dbec5b7c9c
commit 82d3ba61e4

View file

@ -49,20 +49,17 @@ func LastAddress(n *net.IPNet) net.IP {
ip[3]|^n.Mask[3])
}
// GetIpsFromIpRange takes a CIDR range and returns the start and end IP
func GetIpsFromIpRange(host string) (int64, int64, error) {
var ipStart int64
var ipEnd int64
var err error
var parsedRange *net.IPNet
if _, parsedRange, err = net.ParseCIDR(host); err != nil {
return ipStart, ipEnd, fmt.Errorf("'%s' is not a valid CIDR", host)
_, parsedRange, err := net.ParseCIDR(host)
if err != nil {
return 0, 0, fmt.Errorf("'%s' is not a valid CIDR", host)
}
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))
ipEnd = int64(IP2Int(LastAddress(parsedRange)))
ipStart := int64(IP2Int(parsedRange.IP))
ipEnd := int64(IP2Int(LastAddress(parsedRange)))
return ipStart, ipEnd, nil
}