From f6986afe76cc9af7b69dcd8205adab3856529e8b Mon Sep 17 00:00:00 2001 From: xuu Date: Sat, 30 Sep 2023 16:19:41 -0600 Subject: [PATCH] feat: add build info endpoint --- cmd/ev/app.info.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 cmd/ev/app.info.go diff --git a/cmd/ev/app.info.go b/cmd/ev/app.info.go new file mode 100644 index 0000000..94dc0ca --- /dev/null +++ b/cmd/ev/app.info.go @@ -0,0 +1,33 @@ +package main + +import ( + "context" + "fmt" + "net/http" + "runtime/debug" + + "go.sour.is/pkg/lg" + "go.sour.is/pkg/service" +) + +var _ = apps.Register(50, func(ctx context.Context, svc *service.Harness) error { + _, span := lg.Span(ctx) + defer span.End() + + svc.Add(&info{}) + + return nil +}) + +type info struct{} + +func (info) RegisterHTTP(mux *http.ServeMux) { + mux.HandleFunc("/info", func(w http.ResponseWriter, r *http.Request) { + bi, ok := debug.ReadBuildInfo() + if !ok { + fmt.Fprint(w, "Build Info not avalible.") + return + } + fmt.Fprint(w, bi) + }) +}