Skip to content

Commit

Permalink
Include version info in site-info
Browse files Browse the repository at this point in the history
  • Loading branch information
SeraphJACK committed Jan 19, 2024
1 parent e9398f9 commit fa8d61c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions services/basics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package services

import (
"net/http"
"runtime"
"runtime/debug"

"github.com/ProjectAnni/anniv-go/config"
"github.com/ProjectAnni/anniv-go/meta"
Expand All @@ -13,8 +15,25 @@ type SiteInfo struct {
Description string `json:"description"`
ProtocolVersion string `json:"protocol_version"`
Features []string `json:"features"`
Custom any `json:"__anniv-go"`
}

var customInfo = func() any {
info := make(map[string]string)

info["goVersion"] = runtime.Version()

if buildInfo, ok := debug.ReadBuildInfo(); ok {
for _, v := range buildInfo.Settings {
if v.Key == "vcs.revision" || v.Key == "vcs.time" || v.Key == "vcs.modified" {
info[v.Key] = v.Value
}
}
}

return info
}()

func siteInfo() SiteInfo {
features := make([]string, 0)
if config.Cfg.Enforce2FA {
Expand All @@ -33,6 +52,7 @@ func siteInfo() SiteInfo {
Description: config.Cfg.Description,
ProtocolVersion: "1",
Features: features,
Custom: customInfo,
}
}

Expand Down

0 comments on commit fa8d61c

Please sign in to comment.