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

Commit

Permalink
feat(api): add version endpoint (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
s0up4200 authored Nov 5, 2024
1 parent f84f5d9 commit 3113f8d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions internal/http/version.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 3113f8d

Please sign in to comment.