forked from stefanprodan/podinfo
/
info.go
53 lines (46 loc) · 1.39 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
package api
import (
"net/http"
"runtime"
"strconv"
"github.com/feedforwardsystems/podinfo/pkg/version"
)
// Info godoc
// @Summary Runtime information
// @Description returns the runtime information
// @Tags HTTP API
// @Accept json
// @Produce json
// @Success 200 {object} api.RuntimeResponse
// @Router /api/info [get]
func (s *Server) infoHandler(w http.ResponseWriter, r *http.Request) {
_, span := s.tracer.Start(r.Context(), "infoHandler")
defer span.End()
data := RuntimeResponse{
Hostname: s.config.Hostname,
Version: version.VERSION,
Revision: version.REVISION,
Logo: s.config.UILogo,
Color: s.config.UIColor,
Message: s.config.UIMessage,
GOOS: runtime.GOOS,
GOARCH: runtime.GOARCH,
Runtime: runtime.Version(),
NumGoroutine: strconv.FormatInt(int64(runtime.NumGoroutine()), 10),
NumCPU: strconv.FormatInt(int64(runtime.NumCPU()), 10),
}
s.JSONResponse(w, r, data)
}
type RuntimeResponse struct {
Hostname string `json:"hostname"`
Version string `json:"version"`
Revision string `json:"revision"`
Color string `json:"color"`
Logo string `json:"logo"`
Message string `json:"message"`
GOOS string `json:"goos"`
GOARCH string `json:"goarch"`
Runtime string `json:"runtime"`
NumGoroutine string `json:"num_goroutine"`
NumCPU string `json:"num_cpu"`
}