Run go vet using nogo during build step

See https://github.com/bazelbuild/rules_go/blob/master/go/nogo.rst

These are correctness checks, not coding style linters, such that
compilation will fail if they do not pass.

They are also ran for external dependencies, with more or less
fine-grained exclusions.

Test Plan: Ran gazelle.sh and tests.

Bug: T472

X-Origin-Diff: phab/D269
GitOrigin-RevId: f932555ec8cbb9d0c09f2a3c6a0df94a0f6724a8
diff --git a/BUILD b/BUILD
index 4806f47..bc5858d 100644
--- a/BUILD
+++ b/BUILD
@@ -1,8 +1,9 @@
 load("@bazel_gazelle//:def.bzl", "gazelle")
+load("@io_bazel_rules_go//go:def.bzl", "nogo")
 
 # gazelle:prefix git.monogon.dev/source/nexantic.git
 # gazelle:exclude core/generated
-# gazelle:exclude imports.go
+# gazelle:exclude tools.go
 gazelle(name = "gazelle")
 
 # Shortcut for the Go SDK
@@ -10,3 +11,38 @@
     name = "go",
     actual = "@go_sdk//:bin/go",
 )
+
+# nogo linters
+nogo(
+    name = "nogo_vet",
+    config = "nogo_config.json",
+    visibility = ["//visibility:public"],
+    # These deps enable the analyses equivalent to running `go vet`.
+    # Passing vet = True enables only a tiny subset of these (the ones
+    # that are always correct).
+    #
+    # You can see the what `go vet` does by running `go doc cmd/vet`.
+    deps = [
+        "@org_golang_x_tools//go/analysis/passes/asmdecl:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/assign:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/atomic:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/bools:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/buildtag:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/cgocall:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/composite:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/copylock:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/httpresponse:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/loopclosure:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/lostcancel:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/nilfunc:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/printf:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/shift:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/stdmethods:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/structtag:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/tests:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/unmarshal:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/unreachable:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/unsafeptr:go_tool_library",
+        "@org_golang_x_tools//go/analysis/passes/unusedresult:go_tool_library",
+    ],
+)
diff --git a/WORKSPACE b/WORKSPACE
index 0c95a1c..a3224f9 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -61,7 +61,10 @@
 
 go_rules_dependencies()
 
-go_register_toolchains()
+go_register_toolchains(
+    go_version = "1.13",
+    nogo = "@//:nogo_vet",
+)
 
 load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
 
diff --git a/nogo_config.json b/nogo_config.json
new file mode 100644
index 0000000..5c9b28c
--- /dev/null
+++ b/nogo_config.json
@@ -0,0 +1,43 @@
+{
+  "composites": {
+    "exclude_files": {
+      "external/kubernetes/": "third_party",
+      "external/bazel_gazelle/language/go/": "third_party",
+      "external/com_github_golang_protobuf/": "third_party"
+    }
+  },
+  "copylocks": {
+    "exclude_files": {
+      "external/kubernetes/": "third_party"
+    }
+  },
+  "lostcancel": {
+    "exclude_files": {
+      "external/com_github_golang_protobuf/": "third_party",
+      "external/com_github_grpc_ecosystem_grpc_gateway/runtime/": "third_party",
+      "external/kubernetes/staging/src/k8s.io/legacy-cloud-providers/vsphere/": "third_party"
+    }
+  },
+  "unreachable": {
+    "exclude_files": {
+      "external/kubernetes/vendor/gopkg.in/gcfg.v1": "third_party",
+      "external/bazel_gazelle/pathtools": "third_party"
+    }
+  },
+  "assign": {
+    "exclude_files": {
+      "external/bazel_gazelle/walk": "third_party"
+    }
+  },
+  "unsafeptr": {
+    "exclude_files": {
+      "external/kubernetes/vendor/github.com/modern-go/reflect2/": "third_party",
+      "external/com_github_modern_go_reflect2/": "third_party"
+    }
+  },
+  "unusedresult": {
+    "exclude_files": {
+      "external/kubernetes/vendor/github.com/docker/spdystream": "third_party"
+    }
+  }
+}