mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 07:30:55 +00:00
added conditional json flag when trying to view healthchecks
This commit is contained in:
parent
289f86247e
commit
7c575585e9
38
admin.go
38
admin.go
@ -279,9 +279,7 @@ func profIndex(rw http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
execJSON(rw, dataJSON)
|
||||||
rw.Header().Set("Content-Type", "application/json")
|
|
||||||
rw.Write(dataJSON)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,7 +293,7 @@ func profIndex(rw http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// Healthcheck is a http.Handler calling health checking and showing the result.
|
// Healthcheck is a http.Handler calling health checking and showing the result.
|
||||||
// it's in "/healthcheck" pattern in admin module.
|
// it's in "/healthcheck" pattern in admin module.
|
||||||
func healthcheck(rw http.ResponseWriter, _ *http.Request) {
|
func healthcheck(rw http.ResponseWriter, r *http.Request) {
|
||||||
var (
|
var (
|
||||||
result []string
|
result []string
|
||||||
data = make(map[interface{}]interface{})
|
data = make(map[interface{}]interface{})
|
||||||
@ -322,12 +320,44 @@ func healthcheck(rw http.ResponseWriter, _ *http.Request) {
|
|||||||
*resultList = append(*resultList, result)
|
*resultList = append(*resultList, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
queryParams := r.URL.Query()
|
||||||
|
|
||||||
|
if queryParams["json"] != nil {
|
||||||
|
|
||||||
|
type Result map[string]interface{}
|
||||||
|
|
||||||
|
response := make([]Result, len(*resultList))
|
||||||
|
|
||||||
|
for i, currentResult := range *resultList {
|
||||||
|
currentResultMap := make(Result)
|
||||||
|
currentResultMap["name"] = currentResult[0]
|
||||||
|
currentResultMap["message"] = currentResult[1]
|
||||||
|
currentResultMap["status"] = currentResult[2]
|
||||||
|
response[i] = currentResultMap
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONResponse, err := json.Marshal(response)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
|
} else {
|
||||||
|
execJSON(rw, JSONResponse)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
content["Data"] = resultList
|
content["Data"] = resultList
|
||||||
data["Content"] = content
|
data["Content"] = content
|
||||||
data["Title"] = "Health Check"
|
data["Title"] = "Health Check"
|
||||||
|
|
||||||
execTpl(rw, data, healthCheckTpl, defaultScriptsTpl)
|
execTpl(rw, data, healthCheckTpl, defaultScriptsTpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func execJSON(rw http.ResponseWriter, jsonData []byte) {
|
||||||
|
rw.Header().Set("Content-Type", "application/json")
|
||||||
|
rw.Write(jsonData)
|
||||||
|
}
|
||||||
|
|
||||||
// TaskStatus is a http.Handler with running task status (task name, status and the last execution).
|
// TaskStatus is a http.Handler with running task status (task name, status and the last execution).
|
||||||
// it's in "/task" pattern in admin module.
|
// it's in "/task" pattern in admin module.
|
||||||
func taskStatus(rw http.ResponseWriter, req *http.Request) {
|
func taskStatus(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
Loading…
Reference in New Issue
Block a user