mirror of
https://github.com/astaxie/beego.git
synced 2024-11-26 05:11:31 +00:00
remove the dupl
This commit is contained in:
parent
8af8936ee0
commit
e26720496f
108
admin.go
108
admin.go
@ -65,24 +65,15 @@ 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, r *http.Request) {
|
func adminIndex(rw http.ResponseWriter, r *http.Request) {
|
||||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
execTpl(rw, map[interface{}]interface{}{}, indexTpl, defaultScriptsTpl)
|
||||||
tmpl = template.Must(tmpl.Parse(indexTpl))
|
|
||||||
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
|
||||||
data := make(map[interface{}]interface{})
|
|
||||||
tmpl.Execute(rw, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// QpsIndex is the http.Handler for writing qbs statistics map result info in http.ResponseWriter.
|
// QpsIndex is the http.Handler for writing qbs statistics map result info in http.ResponseWriter.
|
||||||
// it's registered with url pattern "/qbs" in admin module.
|
// it's registered with url pattern "/qbs" in admin module.
|
||||||
func qpsIndex(rw http.ResponseWriter, r *http.Request) {
|
func qpsIndex(rw http.ResponseWriter, r *http.Request) {
|
||||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
|
||||||
tmpl = template.Must(tmpl.Parse(qpsTpl))
|
|
||||||
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
|
||||||
data := make(map[interface{}]interface{})
|
data := make(map[interface{}]interface{})
|
||||||
data["Content"] = toolbox.StatisticsMap.GetMap()
|
data["Content"] = toolbox.StatisticsMap.GetMap()
|
||||||
|
execTpl(rw, data, qpsTpl, defaultScriptsTpl)
|
||||||
tmpl.Execute(rw, data)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
@ -167,11 +158,7 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
|
|||||||
content["Methods"] = methods
|
content["Methods"] = methods
|
||||||
data["Content"] = content
|
data["Content"] = content
|
||||||
data["Title"] = "Routers"
|
data["Title"] = "Routers"
|
||||||
|
execTpl(rw, data, routerAndFilterTpl, defaultScriptsTpl)
|
||||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
|
||||||
tmpl = template.Must(tmpl.Parse(routerAndFilterTpl))
|
|
||||||
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
|
||||||
tmpl.Execute(rw, data)
|
|
||||||
case "filter":
|
case "filter":
|
||||||
content := make(map[string]interface{})
|
content := make(map[string]interface{})
|
||||||
|
|
||||||
@ -186,13 +173,17 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
if BeeApp.Handlers.enableFilter {
|
if BeeApp.Handlers.enableFilter {
|
||||||
var filterType string
|
var filterType string
|
||||||
|
for k, fr := range map[int]string{
|
||||||
if bf, ok := BeeApp.Handlers.filters[BeforeRouter]; ok {
|
BeforeStatic: "Before Static",
|
||||||
filterType = "Before Router"
|
BeforeRouter: "Before Router",
|
||||||
|
BeforeExec: "Before Exec",
|
||||||
|
AfterExec: "After Exec",
|
||||||
|
FinishRouter: "Finish Router"} {
|
||||||
|
if bf, ok := BeeApp.Handlers.filters[k]; ok {
|
||||||
|
filterType = fr
|
||||||
filterTypes = append(filterTypes, filterType)
|
filterTypes = append(filterTypes, filterType)
|
||||||
resultList := new([][]string)
|
resultList := new([][]string)
|
||||||
for _, f := range bf {
|
for _, f := range bf {
|
||||||
|
|
||||||
var result = []string{
|
var result = []string{
|
||||||
fmt.Sprintf("%s", f.pattern),
|
fmt.Sprintf("%s", f.pattern),
|
||||||
fmt.Sprintf("%s", utils.GetFuncName(f.filterFunc)),
|
fmt.Sprintf("%s", utils.GetFuncName(f.filterFunc)),
|
||||||
@ -201,50 +192,6 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
filterTypeData[filterType] = resultList
|
filterTypeData[filterType] = resultList
|
||||||
}
|
}
|
||||||
|
|
||||||
if bf, ok := BeeApp.Handlers.filters[BeforeExec]; ok {
|
|
||||||
filterType = "Before Exec"
|
|
||||||
filterTypes = append(filterTypes, filterType)
|
|
||||||
resultList := new([][]string)
|
|
||||||
for _, f := range bf {
|
|
||||||
|
|
||||||
var result = []string{
|
|
||||||
fmt.Sprintf("%s", f.pattern),
|
|
||||||
fmt.Sprintf("%s", utils.GetFuncName(f.filterFunc)),
|
|
||||||
}
|
|
||||||
*resultList = append(*resultList, result)
|
|
||||||
}
|
|
||||||
filterTypeData[filterType] = resultList
|
|
||||||
}
|
|
||||||
|
|
||||||
if bf, ok := BeeApp.Handlers.filters[AfterExec]; ok {
|
|
||||||
filterType = "After Exec"
|
|
||||||
filterTypes = append(filterTypes, filterType)
|
|
||||||
resultList := new([][]string)
|
|
||||||
for _, f := range bf {
|
|
||||||
|
|
||||||
var result = []string{
|
|
||||||
fmt.Sprintf("%s", f.pattern),
|
|
||||||
fmt.Sprintf("%s", utils.GetFuncName(f.filterFunc)),
|
|
||||||
}
|
|
||||||
*resultList = append(*resultList, result)
|
|
||||||
}
|
|
||||||
filterTypeData[filterType] = resultList
|
|
||||||
}
|
|
||||||
|
|
||||||
if bf, ok := BeeApp.Handlers.filters[FinishRouter]; ok {
|
|
||||||
filterType = "Finish Router"
|
|
||||||
filterTypes = append(filterTypes, filterType)
|
|
||||||
resultList := new([][]string)
|
|
||||||
for _, f := range bf {
|
|
||||||
|
|
||||||
var result = []string{
|
|
||||||
fmt.Sprintf("%s", f.pattern),
|
|
||||||
fmt.Sprintf("%s", utils.GetFuncName(f.filterFunc)),
|
|
||||||
}
|
|
||||||
*resultList = append(*resultList, result)
|
|
||||||
}
|
|
||||||
filterTypeData[filterType] = resultList
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,11 +200,7 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
data["Content"] = content
|
data["Content"] = content
|
||||||
data["Title"] = "Filters"
|
data["Title"] = "Filters"
|
||||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
execTpl(rw, data, routerAndFilterTpl, defaultScriptsTpl)
|
||||||
tmpl = template.Must(tmpl.Parse(routerAndFilterTpl))
|
|
||||||
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
|
||||||
tmpl.Execute(rw, data)
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
rw.Write([]byte("command not support"))
|
rw.Write([]byte("command not support"))
|
||||||
}
|
}
|
||||||
@ -306,7 +249,7 @@ func profIndex(rw http.ResponseWriter, r *http.Request) {
|
|||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
command := r.Form.Get("command")
|
command := r.Form.Get("command")
|
||||||
format := r.Form.Get("format")
|
format := r.Form.Get("format")
|
||||||
data := make(map[string]interface{})
|
data := make(map[interface{}]interface{})
|
||||||
|
|
||||||
var result bytes.Buffer
|
var result bytes.Buffer
|
||||||
if command != "" {
|
if command != "" {
|
||||||
@ -326,15 +269,11 @@ func profIndex(rw http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data["Title"] = command
|
data["Title"] = command
|
||||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
defaultTpl := defaultScriptsTpl
|
||||||
tmpl = template.Must(tmpl.Parse(profillingTpl))
|
|
||||||
if command == "gc summary" {
|
if command == "gc summary" {
|
||||||
tmpl = template.Must(tmpl.Parse(gcAjaxTpl))
|
defaultTpl = gcAjaxTpl
|
||||||
} else {
|
|
||||||
|
|
||||||
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
|
||||||
}
|
}
|
||||||
tmpl.Execute(rw, data)
|
execTpl(rw, data, profillingTpl, defaultTpl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,11 +315,7 @@ func healthcheck(rw http.ResponseWriter, req *http.Request) {
|
|||||||
content["Data"] = resultList
|
content["Data"] = resultList
|
||||||
data["Content"] = content
|
data["Content"] = content
|
||||||
data["Title"] = "Health Check"
|
data["Title"] = "Health Check"
|
||||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
execTpl(rw, data, healthCheckTpl, defaultScriptsTpl)
|
||||||
tmpl = template.Must(tmpl.Parse(healthCheckTpl))
|
|
||||||
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
|
||||||
tmpl.Execute(rw, data)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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).
|
||||||
@ -429,9 +364,14 @@ 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
func execTpl(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))
|
||||||
tmpl = template.Must(tmpl.Parse(tasksTpl))
|
for _, tpl := range tpls {
|
||||||
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
tmpl = template.Must(tmpl.Parse(tpl))
|
||||||
|
}
|
||||||
tmpl.Execute(rw, data)
|
tmpl.Execute(rw, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user