mirror of
https://github.com/astaxie/beego.git
synced 2024-11-24 16:50:55 +00:00
renamed functions for clarity
This commit is contained in:
parent
8d1a9bc92e
commit
5a4a082af0
22
admin.go
22
admin.go
@ -71,7 +71,7 @@ func init() {
|
||||
// AdminIndex is the default http.Handler for admin module.
|
||||
// it matches url pattern "/".
|
||||
func adminIndex(rw http.ResponseWriter, _ *http.Request) {
|
||||
execTpl(rw, map[interface{}]interface{}{}, indexTpl, defaultScriptsTpl)
|
||||
writeTemplate(rw, map[interface{}]interface{}{}, indexTpl, defaultScriptsTpl)
|
||||
}
|
||||
|
||||
// QpsIndex is the http.Handler for writing qps statistics map result info in http.ResponseWriter.
|
||||
@ -91,7 +91,7 @@ func qpsIndex(rw http.ResponseWriter, _ *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
execTpl(rw, data, qpsTpl, defaultScriptsTpl)
|
||||
writeTemplate(rw, data, qpsTpl, defaultScriptsTpl)
|
||||
}
|
||||
|
||||
// ListConf is the http.Handler of displaying all beego configuration values as key/value pair.
|
||||
@ -128,7 +128,7 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
data["Content"] = content
|
||||
data["Title"] = "Routers"
|
||||
execTpl(rw, data, routerAndFilterTpl, defaultScriptsTpl)
|
||||
writeTemplate(rw, data, routerAndFilterTpl, defaultScriptsTpl)
|
||||
case "filter":
|
||||
var (
|
||||
content = M{
|
||||
@ -171,7 +171,7 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
|
||||
|
||||
data["Content"] = content
|
||||
data["Title"] = "Filters"
|
||||
execTpl(rw, data, routerAndFilterTpl, defaultScriptsTpl)
|
||||
writeTemplate(rw, data, routerAndFilterTpl, defaultScriptsTpl)
|
||||
default:
|
||||
rw.Write([]byte("command not support"))
|
||||
}
|
||||
@ -279,7 +279,7 @@ func profIndex(rw http.ResponseWriter, r *http.Request) {
|
||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
execJSON(rw, dataJSON)
|
||||
writeJSON(rw, dataJSON)
|
||||
return
|
||||
}
|
||||
|
||||
@ -288,7 +288,7 @@ func profIndex(rw http.ResponseWriter, r *http.Request) {
|
||||
if command == "gc summary" {
|
||||
defaultTpl = gcAjaxTpl
|
||||
}
|
||||
execTpl(rw, data, profillingTpl, defaultTpl)
|
||||
writeTemplate(rw, data, profillingTpl, defaultTpl)
|
||||
}
|
||||
|
||||
// Healthcheck is a http.Handler calling health checking and showing the result.
|
||||
@ -340,7 +340,7 @@ func healthcheck(rw http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||
} else {
|
||||
execJSON(rw, JSONResponse)
|
||||
writeJSON(rw, JSONResponse)
|
||||
}
|
||||
|
||||
return
|
||||
@ -350,10 +350,10 @@ func healthcheck(rw http.ResponseWriter, r *http.Request) {
|
||||
data["Content"] = content
|
||||
data["Title"] = "Health Check"
|
||||
|
||||
execTpl(rw, data, healthCheckTpl, defaultScriptsTpl)
|
||||
writeTemplate(rw, data, healthCheckTpl, defaultScriptsTpl)
|
||||
}
|
||||
|
||||
func execJSON(rw http.ResponseWriter, jsonData []byte) {
|
||||
func writeJSON(rw http.ResponseWriter, jsonData []byte) {
|
||||
rw.Header().Set("Content-Type", "application/json")
|
||||
rw.Write(jsonData)
|
||||
}
|
||||
@ -401,10 +401,10 @@ func taskStatus(rw http.ResponseWriter, req *http.Request) {
|
||||
content["Data"] = resultList
|
||||
data["Content"] = content
|
||||
data["Title"] = "Tasks"
|
||||
execTpl(rw, data, tasksTpl, defaultScriptsTpl)
|
||||
writeTemplate(rw, data, tasksTpl, defaultScriptsTpl)
|
||||
}
|
||||
|
||||
func execTpl(rw http.ResponseWriter, data map[interface{}]interface{}, tpls ...string) {
|
||||
func writeTemplate(rw http.ResponseWriter, data map[interface{}]interface{}, tpls ...string) {
|
||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
||||
for _, tpl := range tpls {
|
||||
tmpl = template.Must(tmpl.Parse(tpl))
|
||||
|
@ -97,7 +97,7 @@ func oldMap() M {
|
||||
return m
|
||||
}
|
||||
|
||||
func TestExecJSON(t *testing.T) {
|
||||
func TestWriteJSON(t *testing.T) {
|
||||
t.Log("Testing the adding of JSON to the response")
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
@ -105,7 +105,7 @@ func TestExecJSON(t *testing.T) {
|
||||
|
||||
res, _ := json.Marshal(originalBody)
|
||||
|
||||
execJSON(w, res)
|
||||
writeJSON(w, res)
|
||||
|
||||
decodedBody := []int{}
|
||||
err := json.NewDecoder(w.Body).Decode(&decodedBody)
|
||||
|
Loading…
Reference in New Issue
Block a user