-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinfo.go
58 lines (53 loc) · 1.53 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
49
50
51
52
53
54
55
56
57
58
package actuator
import (
"net/http"
"runtime"
"time"
)
// 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
)
// application start time stamp
var startupStamp = time.Now().UTC().Format(time.RFC1123Z)
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,
gitCommitAuthorKey: GitCommitAuthor,
gitCommitIDKey: GitCommitID,
gitCommitTimeKey: GitCommitTime,
gitPrimaryBranchKey: GitPrimaryBranch,
gitURLKey: GitURL,
hostNameKey: HostName,
usernameKey: Username,
startupStampKey: startupStamp,
},
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)
}
}