Add Version entry to stats
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2022-07-20 19:55:20 +02:00
parent 764d3be155
commit 0c4bd412c9
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
2 changed files with 16 additions and 0 deletions

View file

@ -1,6 +1,7 @@
FROM golang:1.18-bullseye
COPY . /src/orbeat
COPY .git/ /src/orbeat/.git/
WORKDIR /src/orbeat
RUN GOAMD64=v2 go build -v -o orbeat . && mv orbeat /usr/bin && rm -rf /src/orbeat

View file

@ -23,6 +23,7 @@ import (
"os"
"path"
"runtime"
"runtime/debug"
"strings"
"sync"
"sync/atomic"
@ -47,6 +48,8 @@ var trustedPublicKeys []ed25519.PublicKey
var debugOutput = false
var programVersion = "unknown"
type statistics struct {
Served servedStatistics `json:"served"`
ContentCache contentCacheStatistics `json:"content_cache"`
@ -550,12 +553,14 @@ func handle(ctx httputils.RequestContext) {
ctx.SetResponseCode(http.StatusOK)
statsStruct := struct {
Version string `json:"version"`
Statistics *statistics `json:"statistics"`
Database struct {
TotalEntries uint64 `json:"entries"`
TotalSize uint64 `json:"size"`
} `json:"database"`
}{
Version: programVersion,
Statistics: &globalStatistics,
}
@ -717,6 +722,16 @@ func main() {
var err error
if dInfo, ok := debug.ReadBuildInfo(); ok {
for _, s := range dInfo.Settings {
if s.Key == "vcs.revision" {
programVersion = s.Value
} else if s.Key == "vcs.modified" {
programVersion += "-dev"
}
}
}
for _, k := range strings.Split(*trustedKeys, ",") {
var publicKey ed25519.PublicKey
publicKey, err = MakyuuIchaival.Bech32Encoding.DecodeString(strings.Trim(k, " "))