From 6074ac1ec05ec198f3cb1d5325a6b9bc1192b4a8 Mon Sep 17 00:00:00 2001 From: s0up4200 Date: Mon, 28 Oct 2024 22:46:47 +0100 Subject: [PATCH] feat(api): add version endpoint --- internal/http/server.go | 1 + internal/http/version.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 internal/http/version.go diff --git a/internal/http/server.go b/internal/http/server.go index 04386d9..5d54a88 100644 --- a/internal/http/server.go +++ b/internal/http/server.go @@ -49,6 +49,7 @@ func (s Server) Handler() http.Handler { r.Use(middleware.Logger) r.Route("/api/healthz", newHealthHandler().Routes) + r.Route("/api/version", newVersionHandler().Routes) r.Group(func(r chi.Router) { r.Use(s.isAuthenticated) diff --git a/internal/http/version.go b/internal/http/version.go new file mode 100644 index 0000000..e9bd1bb --- /dev/null +++ b/internal/http/version.go @@ -0,0 +1,34 @@ +package http + +import ( + "net/http" + + "github.com/autobrr/omegabrr/internal/buildinfo" + "github.com/go-chi/chi/v5" + "github.com/go-chi/render" +) + +type versionHandler struct{} + +func newVersionHandler() *versionHandler { + return &versionHandler{} +} + +func (h versionHandler) Routes(r chi.Router) { + r.Get("/", h.handleVersion) +} + +type VersionResponse struct { + Version string `json:"version"` + Commit string `json:"commit"` + Date string `json:"date"` +} + +func (h versionHandler) handleVersion(w http.ResponseWriter, r *http.Request) { + resp := VersionResponse{ + Version: buildinfo.Version, + Commit: buildinfo.Commit, + Date: buildinfo.Date, + } + render.JSON(w, r, resp) +}