mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 13:18:53 +00:00
util/cmpx: delete now that we're using Go 1.22
Updates #11058 Change-Id: I09dea8e86f03ec148b715efca339eab8b1f0f644 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
5ea071186e
commit
2bd3c1474b
@@ -1,22 +0,0 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
// Package cmpx has code that will likely land in a future version of Go, but
|
||||
// we want sooner.
|
||||
package cmpx
|
||||
|
||||
// Or returns the first non-zero element of list, or else returns the zero T.
|
||||
//
|
||||
// This is the proposal from
|
||||
// https://github.com/golang/go/issues/60204#issuecomment-1581245334.
|
||||
func Or[T comparable](list ...T) T {
|
||||
// TODO(bradfitz): remove the comparable constraint so we can use this
|
||||
// with funcs too and use reflect to see whether they're non-zero? 🤷♂️
|
||||
var zero T
|
||||
for _, v := range list {
|
||||
if v != zero {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return zero
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package cmpx
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestOr(t *testing.T) {
|
||||
if g, w := Or[string](), ""; g != w {
|
||||
t.Errorf("got %v; want %v", g, w)
|
||||
}
|
||||
if g, w := Or[int](), 0; g != w {
|
||||
t.Errorf("got %v; want %v", g, w)
|
||||
}
|
||||
if g, w := Or("", "foo", "bar"), "foo"; g != w {
|
||||
t.Errorf("got %v; want %v", g, w)
|
||||
}
|
||||
if g, w := Or("foo", "bar"), "foo"; g != w {
|
||||
t.Errorf("got %v; want %v", g, w)
|
||||
}
|
||||
if g, w := Or("", "", "bar"), "bar"; g != w {
|
||||
t.Errorf("got %v; want %v", g, w)
|
||||
}
|
||||
}
|
@@ -7,6 +7,7 @@
|
||||
package linuxfw
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -17,7 +18,6 @@ import (
|
||||
"github.com/josharian/native"
|
||||
"golang.org/x/sys/unix"
|
||||
"tailscale.com/types/logger"
|
||||
"tailscale.com/util/cmpx"
|
||||
)
|
||||
|
||||
// DebugNetfilter prints debug information about netfilter rules to the
|
||||
@@ -54,18 +54,18 @@ func DebugNetfilter(logf logger.Logf) error {
|
||||
for _, ex := range rule.Exprs {
|
||||
switch v := ex.(type) {
|
||||
case *expr.Meta:
|
||||
key := cmpx.Or(metaKeyNames[v.Key], "UNKNOWN")
|
||||
key := cmp.Or(metaKeyNames[v.Key], "UNKNOWN")
|
||||
logf("netfilter: Meta: key=%s source_register=%v register=%d", key, v.SourceRegister, v.Register)
|
||||
|
||||
case *expr.Cmp:
|
||||
op := cmpx.Or(cmpOpNames[v.Op], "UNKNOWN")
|
||||
op := cmp.Or(cmpOpNames[v.Op], "UNKNOWN")
|
||||
logf("netfilter: Cmp: op=%s register=%d data=%s", op, v.Register, formatMaybePrintable(v.Data))
|
||||
|
||||
case *expr.Counter:
|
||||
// don't print
|
||||
|
||||
case *expr.Verdict:
|
||||
kind := cmpx.Or(verdictNames[v.Kind], "UNKNOWN")
|
||||
kind := cmp.Or(verdictNames[v.Kind], "UNKNOWN")
|
||||
logf("netfilter: Verdict: kind=%s data=%s", kind, v.Chain)
|
||||
|
||||
case *expr.Target:
|
||||
|
Reference in New Issue
Block a user