go-tools/cmd/ev/app.info.go
xuu f6986afe76
All checks were successful
Go Test / test (push) Successful in 52s
Go Test / deploy (push) Successful in 1m34s
feat: add build info endpoint
2023-09-30 16:19:41 -06:00

34 lines
551 B
Go

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