From 6f7a8fa4d4ec786630ed785a43e9a9f18e34426b Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Fri, 26 Apr 2024 14:15:08 -0700 Subject: [PATCH] Add host tool. --- .bazelrc | 2 ++ MODULE.bazel | 9 +++++++++ WORKSPACE | 32 -------------------------------- WORKSPACE.bazel | 11 +++++++++++ cmd/host/README | 5 +++++ cmd/host/main.go | 41 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 68 insertions(+), 32 deletions(-) create mode 100644 .bazelrc create mode 100644 MODULE.bazel delete mode 100644 WORKSPACE create mode 100644 WORKSPACE.bazel create mode 100644 cmd/host/README create mode 100644 cmd/host/main.go diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 0000000..e8138cb --- /dev/null +++ b/.bazelrc @@ -0,0 +1,2 @@ +# Enable Bzlmod for every Bazel command +common --enable_bzlmod diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 0000000..e6cd18a --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,9 @@ +############################################################################### +# Bazel now uses Bzlmod by default to manage external dependencies. +# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel. +# +# For more details, please check https://github.com/bazelbuild/bazel/issues/18958 +############################################################################### + +bazel_dep(name = "rules_go", version = "0.47.0") +bazel_dep(name = "gazelle", version = "0.36.0") \ No newline at end of file diff --git a/WORKSPACE b/WORKSPACE deleted file mode 100644 index 2e1bc16..0000000 --- a/WORKSPACE +++ /dev/null @@ -1,32 +0,0 @@ -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - - -### Go tooling, including Gazelle to generate and maintain BUILD files. -http_archive( - name = "io_bazel_rules_go", - sha256 = "6b65cb7917b4d1709f9410ffe00ecf3e160edf674b78c54a894471320862184f", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.39.0/rules_go-v0.39.0.zip", - "https://github.com/bazelbuild/rules_go/releases/download/v0.39.0/rules_go-v0.39.0.zip", - ], -) - -http_archive( - name = "bazel_gazelle", - sha256 = "ecba0f04f96b4960a5b250c8e8eeec42281035970aa8852dda73098274d14a1d", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.29.0/bazel-gazelle-v0.29.0.tar.gz", - "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.29.0/bazel-gazelle-v0.29.0.tar.gz", - ], -) - -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") -load("//:deps.bzl", "go_dependencies") - -# gazelle:repository_macro deps.bzl%go_dependencies -go_dependencies() -go_rules_dependencies() -go_register_toolchains(version = "1.20.4") -gazelle_dependencies() - diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel new file mode 100644 index 0000000..8be24c8 --- /dev/null +++ b/WORKSPACE.bazel @@ -0,0 +1,11 @@ +### Go tooling, including Gazelle to generate and maintain BUILD files. +load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") +load("//:deps.bzl", "go_dependencies") + +# gazelle:repository_macro deps.bzl%go_dependencies +go_dependencies() +go_rules_dependencies() +go_register_toolchains(version = "1.20.4") +gazelle_dependencies() + diff --git a/cmd/host/README b/cmd/host/README new file mode 100644 index 0000000..24d7e38 --- /dev/null +++ b/cmd/host/README @@ -0,0 +1,5 @@ +host + +This is a utility to display CNAME records and IPs for a hostname. It +was born of my frustration in trying to figure out how to get the host(1) +tool installed on Fedora. \ No newline at end of file diff --git a/cmd/host/main.go b/cmd/host/main.go new file mode 100644 index 0000000..856fbbd --- /dev/null +++ b/cmd/host/main.go @@ -0,0 +1,41 @@ +package main + +import ( + "flag" + "fmt" + "log" + "net" +) + +func lookupHost(host string) error { + cname, err := net.LookupCNAME(host) + if err != nil { + return err + } + + if cname != host { + fmt.Printf("%s is a CNAME for %s\n", host, cname) + host = cname + } + + addrs, err := net.LookupHost(host) + if err != nil { + return err + } + + for _, addr := range addrs { + fmt.Printf("\t%s\n", addr) + } + + return nil +} + +func main() { + flag.Parse() + + for _, arg := range flag.Args() { + if err := lookupHost(arg); err != nil { + log.Println("%s: %s", arg, err) + } + } +}