aboutsummaryrefslogtreecommitdiff
path: root/internal/buildinfo.go
blob: ab1afd49aca45c59eb612740e55cda21102dbb87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package internal

import (
	"encoding/json"
	"log/slog"
	"net/http"
	"runtime/debug"
)

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
		}
	})
}