Change to a go generics set implementation, no more casting 🎉

This commit is contained in:
Kristoffer Dalby 2022-05-30 11:49:35 +02:00
parent fc502e1e79
commit 59a1a85a2b
5 changed files with 10 additions and 23 deletions

View file

@ -9,7 +9,7 @@ import (
"strings"
"time"
"github.com/fatih/set"
mapset "github.com/deckarep/golang-set/v2"
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
"github.com/rs/zerolog/log"
"google.golang.org/protobuf/types/known/timestamppb"
@ -469,17 +469,10 @@ func (h *Headscale) isOutdated(machine *Machine) bool {
return true
}
namespaceSet := set.New(set.ThreadSafe)
namespaceSet := mapset.NewSet[string]()
namespaceSet.Add(machine.Namespace.Name)
namespaces := make([]string, namespaceSet.Size())
for index, namespace := range namespaceSet.List() {
if name, ok := namespace.(string); ok {
namespaces[index] = name
}
}
lastChange := h.getLastStateChange(namespaces...)
lastChange := h.getLastStateChange(namespaceSet.ToSlice()...)
lastUpdate := machine.CreatedAt
if machine.LastSuccessfulUpdate != nil {
lastUpdate = *machine.LastSuccessfulUpdate