1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-24 17:00:55 +00:00

renamed functions for clarity

This commit is contained in:
Eyitayo Ogunbiyi 2020-07-07 14:54:21 +01:00
parent 8d1a9bc92e
commit 5a4a082af0
2 changed files with 13 additions and 13 deletions

View File

@ -71,7 +71,7 @@ func init() {
// AdminIndex is the default http.Handler for admin module. // AdminIndex is the default http.Handler for admin module.
// it matches url pattern "/". // it matches url pattern "/".
func adminIndex(rw http.ResponseWriter, _ *http.Request) { 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. // 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. // 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["Content"] = content
data["Title"] = "Routers" data["Title"] = "Routers"
execTpl(rw, data, routerAndFilterTpl, defaultScriptsTpl) writeTemplate(rw, data, routerAndFilterTpl, defaultScriptsTpl)
case "filter": case "filter":
var ( var (
content = M{ content = M{
@ -171,7 +171,7 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
data["Content"] = content data["Content"] = content
data["Title"] = "Filters" data["Title"] = "Filters"
execTpl(rw, data, routerAndFilterTpl, defaultScriptsTpl) writeTemplate(rw, data, routerAndFilterTpl, defaultScriptsTpl)
default: default:
rw.Write([]byte("command not support")) 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) http.Error(rw, err.Error(), http.StatusInternalServerError)
return return
} }
execJSON(rw, dataJSON) writeJSON(rw, dataJSON)
return return
} }
@ -288,7 +288,7 @@ func profIndex(rw http.ResponseWriter, r *http.Request) {
if command == "gc summary" { if command == "gc summary" {
defaultTpl = gcAjaxTpl defaultTpl = gcAjaxTpl
} }
execTpl(rw, data, profillingTpl, defaultTpl) writeTemplate(rw, data, profillingTpl, defaultTpl)
} }
// Healthcheck is a http.Handler calling health checking and showing the result. // 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 { if err != nil {
http.Error(rw, err.Error(), http.StatusInternalServerError) http.Error(rw, err.Error(), http.StatusInternalServerError)
} else { } else {
execJSON(rw, JSONResponse) writeJSON(rw, JSONResponse)
} }
return return
@ -350,10 +350,10 @@ func healthcheck(rw http.ResponseWriter, r *http.Request) {
data["Content"] = content data["Content"] = content
data["Title"] = "Health Check" 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.Header().Set("Content-Type", "application/json")
rw.Write(jsonData) rw.Write(jsonData)
} }
@ -401,10 +401,10 @@ func taskStatus(rw http.ResponseWriter, req *http.Request) {
content["Data"] = resultList content["Data"] = resultList
data["Content"] = content data["Content"] = content
data["Title"] = "Tasks" 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)) tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
for _, tpl := range tpls { for _, tpl := range tpls {
tmpl = template.Must(tmpl.Parse(tpl)) tmpl = template.Must(tmpl.Parse(tpl))

View File

@ -97,7 +97,7 @@ func oldMap() M {
return m return m
} }
func TestExecJSON(t *testing.T) { func TestWriteJSON(t *testing.T) {
t.Log("Testing the adding of JSON to the response") t.Log("Testing the adding of JSON to the response")
w := httptest.NewRecorder() w := httptest.NewRecorder()
@ -105,7 +105,7 @@ func TestExecJSON(t *testing.T) {
res, _ := json.Marshal(originalBody) res, _ := json.Marshal(originalBody)
execJSON(w, res) writeJSON(w, res)
decodedBody := []int{} decodedBody := []int{}
err := json.NewDecoder(w.Body).Decode(&decodedBody) err := json.NewDecoder(w.Body).Decode(&decodedBody)