feat: added /version endpoint
This commit is contained in:
@@ -138,6 +138,9 @@ func makeServer(db *sql.DB, cfg *config.Config) *http.Server {
|
|||||||
routerConfig := router.Config{
|
routerConfig := router.Config{
|
||||||
Database: db,
|
Database: db,
|
||||||
JWTSecret: cfg.JWTSecret,
|
JWTSecret: cfg.JWTSecret,
|
||||||
|
ServiceVersion: Version,
|
||||||
|
ServiceCommit: Commit,
|
||||||
|
ServiceBuildTime: BuildTime,
|
||||||
}
|
}
|
||||||
mux := router.NewMux(routerConfig)
|
mux := router.NewMux(routerConfig)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/robindittmar/dttmr-api/internal/api/response"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Version struct {
|
||||||
|
Version string `json:"version"`
|
||||||
|
Commit string `json:"commit"`
|
||||||
|
BuildTime string `json:"buildTime"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func VersionHandler(version string, commit string, buildTime string) func(http.ResponseWriter, *http.Request) {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
response.JSON(r.Context(), w, http.StatusOK, Version{
|
||||||
|
Version: version,
|
||||||
|
Commit: commit,
|
||||||
|
BuildTime: buildTime,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,9 @@ import (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
Database *sql.DB
|
Database *sql.DB
|
||||||
JWTSecret string
|
JWTSecret string
|
||||||
|
ServiceVersion string
|
||||||
|
ServiceCommit string
|
||||||
|
ServiceBuildTime string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMux(cfg Config) http.Handler {
|
func NewMux(cfg Config) http.Handler {
|
||||||
@@ -32,6 +35,8 @@ func NewMux(cfg Config) http.Handler {
|
|||||||
protected := middleware.WithJWT(authService)
|
protected := middleware.WithJWT(authService)
|
||||||
|
|
||||||
apiMux := http.NewServeMux()
|
apiMux := http.NewServeMux()
|
||||||
|
apiMux.HandleFunc("GET /version", handler.VersionHandler(
|
||||||
|
cfg.ServiceVersion, cfg.ServiceCommit, cfg.ServiceBuildTime))
|
||||||
apiMux.HandleFunc("GET /health", handler.HealthHandler)
|
apiMux.HandleFunc("GET /health", handler.HealthHandler)
|
||||||
|
|
||||||
// Auth
|
// Auth
|
||||||
|
|||||||
Reference in New Issue
Block a user