Skip to content
This repository was archived by the owner on Dec 26, 2024. It is now read-only.

Commit 3113f8d

Browse files
authored
feat(api): add version endpoint (#94)
1 parent f84f5d9 commit 3113f8d

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

internal/http/server.go

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func (s Server) Handler() http.Handler {
4949
r.Use(middleware.Logger)
5050

5151
r.Route("/api/healthz", newHealthHandler().Routes)
52+
r.Route("/api/version", newVersionHandler().Routes)
5253

5354
r.Group(func(r chi.Router) {
5455
r.Use(s.isAuthenticated)

internal/http/version.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package http
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/autobrr/omegabrr/internal/buildinfo"
7+
"github.com/go-chi/chi/v5"
8+
"github.com/go-chi/render"
9+
)
10+
11+
type versionHandler struct{}
12+
13+
func newVersionHandler() *versionHandler {
14+
return &versionHandler{}
15+
}
16+
17+
func (h versionHandler) Routes(r chi.Router) {
18+
r.Get("/", h.handleVersion)
19+
}
20+
21+
type VersionResponse struct {
22+
Version string `json:"version"`
23+
Commit string `json:"commit"`
24+
Date string `json:"date"`
25+
}
26+
27+
func (h versionHandler) handleVersion(w http.ResponseWriter, r *http.Request) {
28+
resp := VersionResponse{
29+
Version: buildinfo.Version,
30+
Commit: buildinfo.Commit,
31+
Date: buildinfo.Date,
32+
}
33+
render.JSON(w, r, resp)
34+
}

0 commit comments

Comments
 (0)