Added version to landing page

This commit is contained in:
2025-12-30 22:47:52 +01:00
parent d0c177b46e
commit 4e49a38cf9
14 changed files with 341 additions and 16 deletions
+70
View File
@@ -0,0 +1,70 @@
# Version Management
## Current Version: 0.1.30
The backend version is managed in `/backend/config/version.go`.
## Updating the Version
To update the application version:
1. Edit `/backend/config/version.go`
2. Change the `Version` constant:
```go
const Version = "0.1.31" // Update this
```
## Git Commit Information
The git commit hash is automatically detected at runtime from:
1. `GIT_COMMIT` environment variable (preferred for Docker)
2. Git command output (works in development)
3. Falls back to "unknown" if neither is available
## Setting Git Commit in Docker
### Development Environment
Add to `docker/.env`:
```bash
GIT_COMMIT=$(git rev-parse --short HEAD)
```
Then restart the container:
```bash
cd docker
docker-compose -f docker-compose.dev.yml up -d backend-dev
```
### Production Build
Use build-time variable:
```bash
docker build --build-arg GIT_COMMIT=$(git rev-parse --short HEAD) .
```
Or set in docker-compose.yml:
```yaml
environment:
- GIT_COMMIT=${GIT_COMMIT:-unknown}
```
## API Endpoints
- **Public**: `GET /api/public/version` (no authentication)
- **Protected**: `GET /api/version` (requires JWT token)
Both return:
```json
{
"version": "0.1.30",
"gitCommit": "d0c177b"
}
```
## Frontend Integration
The landing page automatically fetches version information from `/api/public/version` and displays it.
To see the version in the frontend, visit: http://localhost:5173
+2
View File
@@ -82,9 +82,11 @@ func main() {
importer.RegisterRoutes(protected)
pdfrender.RegisterRoutes(protected)
transfer.RegisterRoutes(protected)
config.RegisterRoutes(protected)
// Register public routes (no authentication)
pdfrender.RegisterPublicRoutes(r)
config.RegisterPublicRoutes(r)
logger.Info("API-Routen erfolgreich registriert")
+10
View File
@@ -0,0 +1,10 @@
package config
import (
"github.com/gin-gonic/gin"
)
// Versionsinfo returns version and git commit information
func Versionsinfo(c *gin.Context) {
c.JSON(200, GetInfo())
}
+15
View File
@@ -0,0 +1,15 @@
package config
import "github.com/gin-gonic/gin"
// RegisterRoutes registers config-related routes (protected)
func RegisterRoutes(r *gin.RouterGroup) {
r.GET("/version", Versionsinfo)
}
// RegisterPublicRoutes registers public config routes (no auth required)
func RegisterPublicRoutes(r *gin.Engine) {
// Public version endpoint - no authentication required
public := r.Group("/api/public")
public.GET("/version", Versionsinfo)
}
+60
View File
@@ -0,0 +1,60 @@
package config
// Version is the application version
const Version = "0.1.30"
var (
// GitCommit will be set by build flags or detected at runtime
GitCommit = "unknown"
)
// init detects git commit if not set during build
func init() {
/*
if GitCommit == "" {
// Try environment variable first
if envCommit := os.Getenv("GIT_COMMIT"); envCommit != "" {
GitCommit = envCommit
} else {
// Try to detect from git command
GitCommit = detectGitCommit()
}
}
*/
}
/*
// detectGitCommit tries to get the current git commit hash
func detectGitCommit() string {
cmd := exec.Command("git", "rev-parse", "--short", "HEAD")
output, err := cmd.Output()
if err != nil {
return "unknown"
}
return strings.TrimSpace(string(output))
}
*/
// GetVersion returns the current application version
func GetVersion() string {
return Version
}
/*
// GetGitCommit returns the git commit hash
func GetGitCommit() string {
return GitCommit
}
*/
// Info contains version information
type Info struct {
Version string `json:"version"`
GitCommit string `json:"gitCommit"`
}
// GetInfo returns version information as a struct
func GetInfo() Info {
return Info{
Version: Version,
GitCommit: GitCommit,
}
}
+43
View File
@@ -0,0 +1,43 @@
package config
import (
"testing"
)
func TestGetVersion(t *testing.T) {
version := GetVersion()
if version == "" {
t.Error("Version should not be empty")
}
if version != Version {
t.Errorf("Expected version %s, got %s", Version, version)
}
}
/*
func TestGetGitCommit(t *testing.T) {
commit := GetGitCommit()
if commit == "" {
t.Error("GitCommit should not be empty")
}
// Should be either "unknown" or a valid git hash
if commit != "unknown" && len(commit) < 7 {
t.Errorf("Invalid git commit format: %s", commit)
}
}
*/
func TestGetInfo(t *testing.T) {
info := GetInfo()
if info.Version == "" {
t.Error("Info.Version should not be empty")
}
if info.GitCommit == "" {
t.Error("Info.GitCommit should not be empty")
}
if info.Version != Version {
t.Errorf("Expected info.Version %s, got %s", Version, info.Version)
}
}