mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
feat(web,server): expose server version and commit hash in Profile page
Add version and commit_hash fields to the /ping endpoint response, sourced from the existing internal/version package (ldflags or Go build info). The frontend capabilities store reads these values and displays them as badges at the bottom of the Profile page.
This commit is contained in:
@@ -7,12 +7,15 @@ import (
|
||||
"github.com/labstack/echo/v4"
|
||||
|
||||
"github.com/memohai/memoh/internal/boot"
|
||||
"github.com/memohai/memoh/internal/version"
|
||||
)
|
||||
|
||||
type PingResponse struct {
|
||||
Status string `json:"status"`
|
||||
ContainerBackend string `json:"container_backend"`
|
||||
SnapshotSupported bool `json:"snapshot_supported"`
|
||||
Version string `json:"version"`
|
||||
CommitHash string `json:"commit_hash"`
|
||||
}
|
||||
|
||||
type PingHandler struct {
|
||||
@@ -42,6 +45,8 @@ func (h *PingHandler) Ping(c echo.Context) error {
|
||||
Status: "ok",
|
||||
ContainerBackend: h.runtime.ContainerBackend,
|
||||
SnapshotSupported: h.runtime.ContainerBackend != "apple",
|
||||
Version: version.Version,
|
||||
CommitHash: version.ShortCommitHash(),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,9 @@ var (
|
||||
BuildTime = ""
|
||||
)
|
||||
|
||||
// GetInfo returns a formatted version string including the version and commit hash.
|
||||
func GetInfo() string {
|
||||
// EnsureBuildInfo populates CommitHash and BuildTime from Go build info
|
||||
// when they were not set via ldflags.
|
||||
func EnsureBuildInfo() {
|
||||
if CommitHash == "" {
|
||||
if info, ok := debug.ReadBuildInfo(); ok {
|
||||
for _, setting := range info.Settings {
|
||||
@@ -31,15 +32,23 @@ func GetInfo() string {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ShortCommitHash returns the first 7 characters of the commit hash.
|
||||
func ShortCommitHash() string {
|
||||
EnsureBuildInfo()
|
||||
if len(CommitHash) > 7 {
|
||||
return CommitHash[:7]
|
||||
}
|
||||
return CommitHash
|
||||
}
|
||||
|
||||
// GetInfo returns a formatted version string including the version and commit hash.
|
||||
func GetInfo() string {
|
||||
EnsureBuildInfo()
|
||||
res := Version
|
||||
if CommitHash != "" {
|
||||
// Only use the first 7 characters of the commit hash if it's long
|
||||
shortHash := CommitHash
|
||||
if len(shortHash) > 7 {
|
||||
shortHash = shortHash[:7]
|
||||
}
|
||||
res += fmt.Sprintf(" (%s)", shortHash)
|
||||
if h := ShortCommitHash(); h != "" {
|
||||
res += fmt.Sprintf(" (%s)", h)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user