Skip to content
This repository was archived by the owner on Jul 13, 2025. It is now read-only.

Commit e649227

Browse files
authored
cmd/tsidp: fix interface{} linter warnings (tailscale#15729)
Replace all instances of interface{} with any to resolve the golangci-lint errors that appeared in the previous tsidp PR. Updates #cleanup Signed-off-by: Patrick O'Doherty <patrick@tailscale.com>
1 parent b34a2bd commit e649227

File tree

2 files changed

+98
-97
lines changed

2 files changed

+98
-97
lines changed

cmd/tsidp/tsidp.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -543,14 +543,14 @@ type userInfo struct {
543543
}
544544

545545
type capRule struct {
546-
IncludeInUserInfo bool `json:"includeInUserInfo"`
547-
ExtraClaims map[string]interface{} `json:"extraClaims,omitempty"` // list of features peer is allowed to edit
546+
IncludeInUserInfo bool `json:"includeInUserInfo"`
547+
ExtraClaims map[string]any `json:"extraClaims,omitempty"` // list of features peer is allowed to edit
548548
}
549549

550550
// flattenExtraClaims merges all ExtraClaims from a slice of capRule into a single map.
551551
// It deduplicates values for each claim and preserves the original input type:
552-
// scalar values remain scalars, and slices are returned as deduplicated []interface{} slices.
553-
func flattenExtraClaims(rules []capRule) map[string]interface{} {
552+
// scalar values remain scalars, and slices are returned as deduplicated []any slices.
553+
func flattenExtraClaims(rules []capRule) map[string]any {
554554
// sets stores deduplicated stringified values for each claim key.
555555
sets := make(map[string]map[string]struct{})
556556

@@ -561,7 +561,7 @@ func flattenExtraClaims(rules []capRule) map[string]interface{} {
561561
for claim, raw := range rule.ExtraClaims {
562562
// Track whether the claim was provided as a slice
563563
switch raw.(type) {
564-
case []string, []interface{}:
564+
case []string, []any:
565565
isSlice[claim] = true
566566
default:
567567
// Only mark as scalar if this is the first time we've seen this claim
@@ -576,11 +576,11 @@ func flattenExtraClaims(rules []capRule) map[string]interface{} {
576576
}
577577

578578
// Build final result: either scalar or slice depending on original type
579-
result := make(map[string]interface{})
579+
result := make(map[string]any)
580580
for claim, valSet := range sets {
581581
if isSlice[claim] {
582-
// Claim was provided as a slice: output as []interface{}
583-
var vals []interface{}
582+
// Claim was provided as a slice: output as []any
583+
var vals []any
584584
for val := range valSet {
585585
vals = append(vals, val)
586586
}
@@ -600,7 +600,7 @@ func flattenExtraClaims(rules []capRule) map[string]interface{} {
600600
// addClaimValue adds a claim value to the deduplication set for a given claim key.
601601
// It accepts scalars (string, int, float64), slices of strings or interfaces,
602602
// and recursively handles nested slices. Unsupported types are ignored with a log message.
603-
func addClaimValue(sets map[string]map[string]struct{}, claim string, val interface{}) {
603+
func addClaimValue(sets map[string]map[string]struct{}, claim string, val any) {
604604
switch v := val.(type) {
605605
case string, float64, int, int64:
606606
// Ensure the claim set is initialized
@@ -620,7 +620,7 @@ func addClaimValue(sets map[string]map[string]struct{}, claim string, val interf
620620
sets[claim][s] = struct{}{}
621621
}
622622

623-
case []interface{}:
623+
case []any:
624624
// Recursively handle each item in the slice
625625
for _, item := range v {
626626
addClaimValue(sets, claim, item)
@@ -633,7 +633,7 @@ func addClaimValue(sets map[string]map[string]struct{}, claim string, val interf
633633
}
634634

635635
// withExtraClaims merges flattened extra claims from a list of capRule into the provided struct v,
636-
// returning a map[string]interface{} that combines both sources.
636+
// returning a map[string]any that combines both sources.
637637
//
638638
// v is any struct whose fields represent static claims; it is first marshaled to JSON, then unmarshalled into a generic map.
639639
// rules is a slice of capRule objects that may define additional (extra) claims to merge.
@@ -643,15 +643,15 @@ func addClaimValue(sets map[string]map[string]struct{}, claim string, val interf
643643
// If an extra claim attempts to overwrite a protected claim, an error is returned.
644644
//
645645
// Returns the merged claims map or an error if any protected claim is violated or JSON (un)marshaling fails.
646-
func withExtraClaims(v any, rules []capRule) (map[string]interface{}, error) {
646+
func withExtraClaims(v any, rules []capRule) (map[string]any, error) {
647647
// Marshal the static struct
648648
data, err := json.Marshal(v)
649649
if err != nil {
650650
return nil, err
651651
}
652652

653653
// Unmarshal into a generic map
654-
var claimMap map[string]interface{}
654+
var claimMap map[string]any
655655
if err := json.Unmarshal(data, &claimMap); err != nil {
656656
return nil, err
657657
}

0 commit comments

Comments
 (0)