package handler

import (
	"net/http"
	"runtime"

	"github.com/gin-gonic/gin"
)

// 版本信息：由 cmd/main.go 将 CI 的 ldflags 注入值赋入，保证单一数据源
var (
	Version   = "dev"
	BuildTime = "unknown"
	CommitSha = "unknown"
)

// VersionInfo 版本信息
type VersionInfo struct {
	Version   string `json:"version"`
	BuildTime string `json:"buildTime"`
	CommitSha string `json:"commitSha"`
	GoVersion string `json:"goVersion"`
}

// GetVersion 获取服务器版本信息
func GetVersion(c *gin.Context) {
	c.JSON(http.StatusOK, VersionInfo{
		Version:   Version,
		BuildTime: BuildTime,
		CommitSha: CommitSha,
		GoVersion: runtime.Version(),
	})
}
