From b17f20f3e30c4a39033d210f2d86ffd005a9ea76 Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Sat, 29 Jul 2023 14:13:50 -0400 Subject: internal: more debug routes Signed-off-by: Xe Iaso --- flake.nix | 1 + internal/buildinfo.go | 26 ++++++++++++++++++++++++++ internal/license.go | 10 ++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 internal/buildinfo.go diff --git a/flake.nix b/flake.nix index 25bc2e6..c6403aa 100644 --- a/flake.nix +++ b/flake.nix @@ -323,6 +323,7 @@ gowasi ]; + GOAMD64 = "v3"; XEDN_STATIC = self.packages.${system}.xedn-static; }; }) // { diff --git a/internal/buildinfo.go b/internal/buildinfo.go new file mode 100644 index 0000000..b3f7390 --- /dev/null +++ b/internal/buildinfo.go @@ -0,0 +1,26 @@ +package internal + +import ( + "encoding/json" + "net/http" + "runtime/debug" + + "golang.org/x/exp/slog" +) + +func init() { + http.HandleFunc("/.within/debug/buildinfo", func(w http.ResponseWriter, r *http.Request) { + bi, ok := debug.ReadBuildInfo() + if !ok { + slog.Error("can't read build info") + http.Error(w, "no build info available", http.StatusInternalServerError) + return + } + + if err := json.NewEncoder(w).Encode(bi); err != nil { + slog.Error("can't encode build info", "err", err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + }) +} diff --git a/internal/license.go b/internal/license.go index bb4dc0b..7eead24 100644 --- a/internal/license.go +++ b/internal/license.go @@ -5,8 +5,8 @@ import ( "net/http" "os" - "within.website/x/cmd/license/licenses" "go4.org/legal" + "within.website/x/cmd/license/licenses" ) func init() { @@ -17,10 +17,16 @@ func init() { fmt.Fprintf(w, "Licenses for this program: %s\n", os.Args[0]) for _, li := range legal.Licenses() { - fmt.Fprintln(w, li) fmt.Fprintln(w) + fmt.Fprintln(w, "---") + fmt.Fprintln(w) + fmt.Fprintln(w, li) } + fmt.Fprintln(w) + fmt.Fprintln(w, "---") + fmt.Fprintln(w) + fmt.Fprintln(w, "Be well, Creator.") }) } -- cgit v1.2.3