diff options
| author | salman <salman@tailscale.com> | 2023-05-05 16:47:28 +0100 |
|---|---|---|
| committer | salman <salman@tailscale.com> | 2023-05-06 11:36:42 +0100 |
| commit | 8e6f564f7e23eded646484e2074c41fdd4c3e171 (patch) | |
| tree | d671b48831f408f7c9f514ce54878e1464042e56 /util | |
| parent | 5783adcc6fc469c0791ca339876d6847cfcc1b01 (diff) | |
| download | tailscale-s/eq.tar.xz tailscale-s/eq.zip | |
cmd/equaler: add command to generate Equal() methodss/eq
The generator is still crude and do not cover most types, but it
covers all the ones needed by the tailcfg package. It's a start.
Fixes #8077.
Signed-off-by: salman <salman@tailscale.com>
Diffstat (limited to 'util')
| -rw-r--r-- | util/codegen/codegen.go | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/util/codegen/codegen.go b/util/codegen/codegen.go index b1e012fad..277d39097 100644 --- a/util/codegen/codegen.go +++ b/util/codegen/codegen.go @@ -16,6 +16,7 @@ import ( "reflect" "strings" + "golang.org/x/exp/slices" "golang.org/x/tools/go/packages" "golang.org/x/tools/imports" "tailscale.com/util/mak" @@ -47,12 +48,13 @@ func LoadTypes(buildTags string, pkgName string) (*packages.Package, map[string] // HasNoClone reports whether the provided tag has `codegen:noclone`. func HasNoClone(structTag string) bool { val := reflect.StructTag(structTag).Get("codegen") - for _, v := range strings.Split(val, ",") { - if v == "noclone" { - return true - } - } - return false + return slices.Contains(strings.Split(val, ","), "noclone") +} + +// HasNoEqual reports whether the provided tag has `codegen:noequal`. +func HasNoEqual(structTag string) bool { + val := reflect.StructTag(structTag).Get("codegen") + return slices.Contains(strings.Split(val, ","), "noequal") } const copyrightHeader = `// Copyright (c) Tailscale Inc & AUTHORS |
