forked from socialsky-io/go-actuator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinfo.go
48 lines (44 loc) · 1.19 KB
/
info.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
package actuator
import (
"net/http"
"runtime"
)
// Set of linked build time variables for providing relevant information for the application
var (
BuildStamp string
GitCommitAuthor string
GitCommitID string
GitCommitTime string
GitPrimaryBranch string
GitURL string
HostName string
Username string
)
func getInfo(config *Config) map[string]interface{} {
return map[string]interface{}{
applicationKey: map[string]string{
EnvKey: config.Env,
nameKey: config.Name,
versionKey: config.Version,
},
gitKey: map[string]string{
buildStampKey: BuildStamp,
hostNameKey: HostName,
usernameKey: Username,
},
runtimeKey: map[string]interface{}{
archKey: runtime.GOARCH,
osKey: runtime.GOOS,
portKey: config.Port,
runtimeVersionKey: runtime.Version(),
},
}
}
// getInfoHandler is used to get the handler function for the info endpoint
func getInfoHandler(config *Config) http.HandlerFunc {
info, _ := encodeJSON(getInfo(config))
return func(writer http.ResponseWriter, _ *http.Request) {
writer.Header().Add(contentTypeHeader, applicationJSONContentType)
_, _ = writer.Write(info)
}
}