Add commit hash to version API

Signed-off-by: Brian Meek <brian@hntlabs.com>
This commit is contained in:
Brian Meek 2022-09-15 12:17:41 -07:00 committed by Tak Wai Wong
parent 1f2f42494c
commit db91fce6f0
No known key found for this signature in database
GPG key ID: 222E4AF2AA1F467D

View file

@ -19,6 +19,8 @@ import (
"net/http"
"strings"
"runtime/debug"
"github.com/gorilla/mux"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
@ -42,6 +44,17 @@ import (
userapi "github.com/matrix-org/dendrite/userapi/api"
)
var commitHash = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
}
}
}
return ""
}()
// Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client
// to clients which need to make outbound HTTP requests.
//
@ -103,6 +116,7 @@ func Setup(
JSON: struct {
Versions []string `json:"versions"`
UnstableFeatures map[string]bool `json:"unstable_features"`
CommitHash string `json:"commit_hash"`
}{Versions: []string{
"r0.0.1",
"r0.1.0",
@ -114,7 +128,7 @@ func Setup(
"v1.0",
"v1.1",
"v1.2",
}, UnstableFeatures: unstableFeatures},
}, UnstableFeatures: unstableFeatures, CommitHash: commitHash},
}
}),
).Methods(http.MethodGet, http.MethodOptions)