-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
48 lines (37 loc) · 1.17 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
package version
import (
"net/http"
"os"
rd "runtime/debug"
json "github.com/goccy/go-json"
"github.com/gofiber/adaptor/v2"
"github.com/pubgo/funk/assert"
"github.com/pubgo/funk/running"
"github.com/pubgo/lava/core/debug"
)
func init() {
debug.Get("/env", adaptor.HTTPHandlerFunc(envHandle))
debug.Get("/version", adaptor.HTTPHandlerFunc(versionHandle))
debug.Get("/dep", adaptor.HTTPHandlerFunc(depHandle))
}
func envHandle(writer http.ResponseWriter, request *http.Request) {
writer.Header().Set("Content-Type", "application/json")
dt := assert.Must1(json.Marshal(os.Environ()))
assert.Must1(writer.Write(dt))
}
func versionHandle(writer http.ResponseWriter, request *http.Request) {
writer.Header().Set("Content-Type", "application/json")
dt := assert.Must1(json.Marshal(running.GetSysInfo()))
assert.Must1(writer.Write(dt))
}
func depHandle(writer http.ResponseWriter, request *http.Request) {
writer.Header().Set("Content-Type", "application/json")
info, ok := rd.ReadBuildInfo()
if !ok {
writer.WriteHeader(http.StatusNoContent)
assert.Must1(writer.Write([]byte("")))
return
}
dt := assert.Must1(json.Marshal(info))
assert.Must1(writer.Write(dt))
}