modernize: run gopls modernize to bring up to 1.25 (#2920)

This commit is contained in:
Kristoffer Dalby
2025-12-01 19:40:25 +01:00
committed by GitHub
parent bfcd9d261d
commit eec196d200
18 changed files with 78 additions and 116 deletions

View File

@@ -3,6 +3,7 @@ package v2
import (
"errors"
"fmt"
"slices"
"time"
"github.com/juanfont/headscale/hscontrol/types"
@@ -178,11 +179,8 @@ func (pol *Policy) compileACLWithAutogroupSelf(
for _, ips := range resolvedSrcIPs {
for _, n := range sameUserNodes {
// Check if any of this node's IPs are in the source set
for _, nodeIP := range n.IPs() {
if ips.Contains(nodeIP) {
n.AppendToIPSet(&srcIPs)
break
}
if slices.ContainsFunc(n.IPs(), ips.Contains) {
n.AppendToIPSet(&srcIPs)
}
}
}
@@ -375,11 +373,8 @@ func (pol *Policy) compileSSHPolicy(
var filteredSrcIPs netipx.IPSetBuilder
for _, n := range sameUserNodes {
// Check if any of this node's IPs are in the source set
for _, nodeIP := range n.IPs() {
if srcIPs.Contains(nodeIP) {
n.AppendToIPSet(&filteredSrcIPs)
break // Found this node, move to next
}
if slices.ContainsFunc(n.IPs(), srcIPs.Contains) {
n.AppendToIPSet(&filteredSrcIPs) // Found this node, move to next
}
}

View File

@@ -3,6 +3,7 @@ package v2
import (
"encoding/json"
"net/netip"
"slices"
"strings"
"testing"
"time"
@@ -906,14 +907,7 @@ func TestCompileFilterRulesForNodeWithAutogroupSelf(t *testing.T) {
}
for _, expectedIP := range expectedDestIPs {
found := false
for _, actualIP := range actualDestIPs {
if actualIP == expectedIP {
found = true
break
}
}
found := slices.Contains(actualDestIPs, expectedIP)
if !found {
t.Errorf("expected destination IP %s to be included, got: %v", expectedIP, actualDestIPs)

View File

@@ -1007,7 +1007,7 @@ func (g Groups) Contains(group *Group) error {
// with "group:". If any group name is invalid, an error is returned.
func (g *Groups) UnmarshalJSON(b []byte) error {
// First unmarshal as a generic map to validate group names first
var rawMap map[string]interface{}
var rawMap map[string]any
if err := json.Unmarshal(b, &rawMap); err != nil {
return err
}
@@ -1024,7 +1024,7 @@ func (g *Groups) UnmarshalJSON(b []byte) error {
rawGroups := make(map[string][]string)
for key, value := range rawMap {
switch v := value.(type) {
case []interface{}:
case []any:
// Convert []interface{} to []string
var stringSlice []string
for _, item := range v {

View File

@@ -39,9 +39,10 @@ func parsePortRange(portDef string) ([]tailcfg.PortRange, error) {
}
var portRanges []tailcfg.PortRange
parts := strings.Split(portDef, ",")
for _, part := range parts {
parts := strings.SplitSeq(portDef, ",")
for part := range parts {
if strings.Contains(part, "-") {
rangeParts := strings.Split(part, "-")
rangeParts = slices.DeleteFunc(rangeParts, func(e string) bool {