mirror of
https://github.com/ngoduykhanh/wireguard-ui
synced 2024-06-02 14:02:13 +02:00
Fix duplicated IPs address suggestions
Use Go 1.21+ stdlib's package slices to filter duplicated suggestions Signed-off-by: Angel Iglesias <angel.iglesias@merlinsoftware.es>
This commit is contained in:
parent
fd5f8fe68b
commit
38fc0868a8
|
@ -9,6 +9,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -1018,10 +1019,14 @@ func SuggestIPAllocation(db store.IStore) echo.HandlerFunc {
|
||||||
fmt.Sprintf("Cannot suggest ip allocation: failed to get available ip from network %s", cidr),
|
fmt.Sprintf("Cannot suggest ip allocation: failed to get available ip from network %s", cidr),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
var newAddr string
|
||||||
if strings.Contains(ip, ":") {
|
if strings.Contains(ip, ":") {
|
||||||
suggestedIPs = append(suggestedIPs, fmt.Sprintf("%s/128", ip))
|
newAddr = fmt.Sprintf("%s/128", ip)
|
||||||
} else {
|
} else {
|
||||||
suggestedIPs = append(suggestedIPs, fmt.Sprintf("%s/32", ip))
|
newAddr = fmt.Sprintf("%s/32", ip)
|
||||||
|
}
|
||||||
|
if !slices.Contains(suggestedIPs, newAddr) {
|
||||||
|
suggestedIPs = slices.Insert(suggestedIPs, len(suggestedIPs), newAddr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue