-
Notifications
You must be signed in to change notification settings - Fork 10
/
version.go
55 lines (46 loc) · 1.23 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2022-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package service
import (
"encoding/json"
"net/http"
"runtime"
"github.com/mattermost/mattermost/server/public/shared/mlog"
)
var (
buildVersion string
buildHash string
buildDate string
)
type VersionInfo struct {
BuildDate string `json:"buildDate"`
BuildVersion string `json:"buildVersion"`
BuildHash string `json:"buildHash"`
GoVersion string `json:"goVersion"`
}
func getVersionInfo() VersionInfo {
return VersionInfo{
BuildDate: buildDate,
BuildVersion: buildVersion,
BuildHash: buildHash,
GoVersion: runtime.Version(),
}
}
func (v VersionInfo) logFields() []mlog.Field {
return []mlog.Field{
mlog.String("buildDate", v.BuildDate),
mlog.String("buildVersion", v.BuildVersion),
mlog.String("buildHash", v.BuildHash),
mlog.String("goVersion", v.GoVersion),
}
}
func (s *Service) getVersion(w http.ResponseWriter, req *http.Request) {
if req.Method != http.MethodGet {
http.NotFound(w, req)
return
}
w.Header().Add("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(getVersionInfo()); err != nil {
s.log.Error("failed to encode data", mlog.Err(err))
}
}