Pass Slice by reference, not value

This commit is contained in:
2023-03-31 16:22:01 +02:00
parent 8488a9e4cd
commit 6d14614043
3 changed files with 19 additions and 19 deletions

View File

@@ -6,18 +6,18 @@ import (
"reflect"
)
func IPNetIndexByIP(list []net.IPNet, ip net.IP) (int, error) {
for index, ipNetEntry := range list {
if ipNetEntry.Contains(ip) {
func IPNetIndexByIP(list *[]net.IPNet, ip *net.IP) (int, error) {
for index, ipNetEntry := range *list {
if ipNetEntry.Contains(*ip) {
return index, nil
}
}
return -1, fmt.Errorf("ip not in ipNet-list")
}
func IPNetIndexByIPNet(list []net.IPNet, ipNet net.IPNet) (int, error) {
for index, ipNetEntry := range list {
if reflect.DeepEqual(ipNetEntry, ipNet) {
func IPNetIndexByIPNet(list *[]net.IPNet, ipNet *net.IPNet) (int, error) {
for index, ipNetEntry := range *list {
if reflect.DeepEqual(ipNetEntry, *ipNet) {
return index, nil
}
}