forked from SkySoft-ATM/gorillaz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.go
More file actions
49 lines (42 loc) · 1.27 KB
/
version.go
File metadata and controls
49 lines (42 loc) · 1.27 KB
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
package gorillaz
import (
"encoding/json"
"go.uber.org/zap"
"net/http"
)
// set at build time, go build -ldflags "-X github.com/skysoft-atm/gorillaz.ApplicationVersion=v0.3.2 -X github.com/skysoft-atm/gorillaz.ApplicationName=srv-cheesy-cheese -X github.com/skysoft-atm/gorillaz.ApplicationDescription=bla_pepito"
var (
ApplicationVersion string
ApplicationDescription string
ApplicationName string
)
func versionInfoHandler() func(http.ResponseWriter, *http.Request) {
// generate the info value from ApplicationVersion, ApplicationDescription and ApplicationName
inf := Info{
App: App{
Version: ApplicationVersion,
Description: ApplicationDescription,
Name: ApplicationName,
},
}
info, err := json.MarshalIndent(inf, "", " ")
// there is no reason for this to happen, so panic
if err != nil {
panic("failed to marshal build information data")
}
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
_, err := w.Write(info)
if err != nil {
Log.Error("failed to write response", zap.Error(err))
}
}
}
type Info struct {
App App `json:"app"`
}
type App struct {
Version string `json:"version"`
Description string `json:"description"`
Name string `json:"name"`
}