Added version to landing page
This commit is contained in:
@@ -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())
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user