Exemple #1
0
// ListConf is the http.Handler of displaying all beego configuration values as key/value pair.
// it's registered with url pattern "/listconf" in admin module.
func listConf(rw http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	command := r.Form.Get("command")
	if command != "" {
		data := make(map[interface{}]interface{})
		switch command {
		case "conf":
			m := make(map[string]interface{})

			m["AppName"] = AppName
			m["AppPath"] = AppPath
			m["AppConfigPath"] = AppConfigPath
			m["StaticDir"] = StaticDir
			m["StaticExtensionsToGzip"] = StaticExtensionsToGzip
			m["HttpAddr"] = HttpAddr
			m["HttpPort"] = HttpPort
			m["HttpTLS"] = EnableHttpTLS
			m["HttpCertFile"] = HttpCertFile
			m["HttpKeyFile"] = HttpKeyFile
			m["RecoverPanic"] = RecoverPanic
			m["AutoRender"] = AutoRender
			m["ViewsPath"] = ViewsPath
			m["RunMode"] = RunMode
			m["SessionOn"] = SessionOn
			m["SessionProvider"] = SessionProvider
			m["SessionName"] = SessionName
			m["SessionGCMaxLifetime"] = SessionGCMaxLifetime
			m["SessionSavePath"] = SessionSavePath
			m["SessionCookieLifeTime"] = SessionCookieLifeTime
			m["UseFcgi"] = UseFcgi
			m["MaxMemory"] = MaxMemory
			m["EnableGzip"] = EnableGzip
			m["DirectoryIndex"] = DirectoryIndex
			m["HttpServerTimeOut"] = HttpServerTimeOut
			m["ErrorsShow"] = ErrorsShow
			m["XSRFKEY"] = XSRFKEY
			m["EnableXSRF"] = EnableXSRF
			m["XSRFExpire"] = XSRFExpire
			m["CopyRequestBody"] = CopyRequestBody
			m["TemplateLeft"] = TemplateLeft
			m["TemplateRight"] = TemplateRight
			m["BeegoServerName"] = BeegoServerName
			m["EnableAdmin"] = EnableAdmin
			m["AdminHttpAddr"] = AdminHttpAddr
			m["AdminHttpPort"] = AdminHttpPort

			tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
			tmpl = template.Must(tmpl.Parse(configTpl))
			tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))

			data["Content"] = m

			tmpl.Execute(rw, data)

		case "router":
			content := make(map[string]interface{})

			var fields = []string{
				fmt.Sprintf("Router Pattern"),
				fmt.Sprintf("Methods"),
				fmt.Sprintf("Controller"),
			}
			content["Fields"] = fields

			methods := []string{}
			methodsData := make(map[string]interface{})
			for method, t := range BeeApp.Handlers.routers {

				resultList := new([][]string)

				printTree(resultList, t)

				methods = append(methods, method)
				methodsData[method] = resultList
			}

			content["Data"] = methodsData
			content["Methods"] = methods
			data["Content"] = content
			data["Title"] = "Routers"

			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":
			content := make(map[string]interface{})

			var fields = []string{
				fmt.Sprintf("Router Pattern"),
				fmt.Sprintf("Filter Function"),
			}
			content["Fields"] = fields

			filterTypes := []string{}
			filterTypeData := make(map[string]interface{})

			if BeeApp.Handlers.enableFilter {
				var filterType string

				if bf, ok := BeeApp.Handlers.filters[BeforeRouter]; ok {
					filterType = "Before 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
				}

				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
				}
			}

			content["Data"] = filterTypeData
			content["Methods"] = filterTypes

			data["Content"] = content
			data["Title"] = "Filters"
			tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
			tmpl = template.Must(tmpl.Parse(routerAndFilterTpl))
			tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
			tmpl.Execute(rw, data)

		default:
			rw.Write([]byte("command not support"))
		}
	} else {
	}
}
Exemple #2
0
// ListConf is the http.Handler of displaying all beego configuration values as key/value pair.
// it's registered with url pattern "/listconf" in admin module.
func ListConf(rw http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	command := r.Form.Get("command")
	if command != "" {
		switch command {
		case "conf":
			fmt.Fprintln(rw, "list all beego's conf:")
			fmt.Fprintln(rw, "AppName:", AppName)
			fmt.Fprintln(rw, "AppPath:", AppPath)
			fmt.Fprintln(rw, "AppConfigPath:", AppConfigPath)
			fmt.Fprintln(rw, "StaticDir:", StaticDir)
			fmt.Fprintln(rw, "StaticExtensionsToGzip:", StaticExtensionsToGzip)
			fmt.Fprintln(rw, "HttpAddr:", HttpAddr)
			fmt.Fprintln(rw, "HttpPort:", HttpPort)
			fmt.Fprintln(rw, "HttpTLS:", HttpTLS)
			fmt.Fprintln(rw, "HttpCertFile:", HttpCertFile)
			fmt.Fprintln(rw, "HttpKeyFile:", HttpKeyFile)
			fmt.Fprintln(rw, "RecoverPanic:", RecoverPanic)
			fmt.Fprintln(rw, "AutoRender:", AutoRender)
			fmt.Fprintln(rw, "ViewsPath:", ViewsPath)
			fmt.Fprintln(rw, "RunMode:", RunMode)
			fmt.Fprintln(rw, "SessionOn:", SessionOn)
			fmt.Fprintln(rw, "SessionProvider:", SessionProvider)
			fmt.Fprintln(rw, "SessionName:", SessionName)
			fmt.Fprintln(rw, "SessionGCMaxLifetime:", SessionGCMaxLifetime)
			fmt.Fprintln(rw, "SessionSavePath:", SessionSavePath)
			fmt.Fprintln(rw, "SessionHashFunc:", SessionHashFunc)
			fmt.Fprintln(rw, "SessionHashKey:", SessionHashKey)
			fmt.Fprintln(rw, "SessionCookieLifeTime:", SessionCookieLifeTime)
			fmt.Fprintln(rw, "UseFcgi:", UseFcgi)
			fmt.Fprintln(rw, "MaxMemory:", MaxMemory)
			fmt.Fprintln(rw, "EnableGzip:", EnableGzip)
			fmt.Fprintln(rw, "DirectoryIndex:", DirectoryIndex)
			fmt.Fprintln(rw, "EnableHotUpdate:", EnableHotUpdate)
			fmt.Fprintln(rw, "HttpServerTimeOut:", HttpServerTimeOut)
			fmt.Fprintln(rw, "ErrorsShow:", ErrorsShow)
			fmt.Fprintln(rw, "XSRFKEY:", XSRFKEY)
			fmt.Fprintln(rw, "EnableXSRF:", EnableXSRF)
			fmt.Fprintln(rw, "XSRFExpire:", XSRFExpire)
			fmt.Fprintln(rw, "CopyRequestBody:", CopyRequestBody)
			fmt.Fprintln(rw, "TemplateLeft:", TemplateLeft)
			fmt.Fprintln(rw, "TemplateRight:", TemplateRight)
			fmt.Fprintln(rw, "BeegoServerName:", BeegoServerName)
			fmt.Fprintln(rw, "EnableAdmin:", EnableAdmin)
			fmt.Fprintln(rw, "AdminHttpAddr:", AdminHttpAddr)
			fmt.Fprintln(rw, "AdminHttpPort:", AdminHttpPort)
		case "router":
			fmt.Fprintln(rw, "Print all router infomation:")
			for _, router := range BeeApp.Handlers.fixrouters {
				if router.hasMethod {
					fmt.Fprintln(rw, router.pattern, "----", router.methods, "----", router.controllerType.Name())
				} else {
					fmt.Fprintln(rw, router.pattern, "----", router.controllerType.Name())
				}
			}
			for _, router := range BeeApp.Handlers.routers {
				if router.hasMethod {
					fmt.Fprintln(rw, router.pattern, "----", router.methods, "----", router.controllerType.Name())
				} else {
					fmt.Fprintln(rw, router.pattern, "----", router.controllerType.Name())
				}
			}
			if BeeApp.Handlers.enableAuto {
				for controllerName, methodObj := range BeeApp.Handlers.autoRouter {
					fmt.Fprintln(rw, controllerName, "----")
					for methodName, obj := range methodObj {
						fmt.Fprintln(rw, "        ", methodName, "-----", obj.Name())
					}
				}
			}
		case "filter":
			fmt.Fprintln(rw, "Print all filter infomation:")
			if BeeApp.Handlers.enableFilter {
				fmt.Fprintln(rw, "BeforeRouter:")
				if bf, ok := BeeApp.Handlers.filters[BeforeRouter]; ok {
					for _, f := range bf {
						fmt.Fprintln(rw, f.pattern, utils.GetFuncName(f.filterFunc))
					}
				}
				fmt.Fprintln(rw, "AfterStatic:")
				if bf, ok := BeeApp.Handlers.filters[AfterStatic]; ok {
					for _, f := range bf {
						fmt.Fprintln(rw, f.pattern, utils.GetFuncName(f.filterFunc))
					}
				}
				fmt.Fprintln(rw, "BeforeExec:")
				if bf, ok := BeeApp.Handlers.filters[BeforeExec]; ok {
					for _, f := range bf {
						fmt.Fprintln(rw, f.pattern, utils.GetFuncName(f.filterFunc))
					}
				}
				fmt.Fprintln(rw, "AfterExec:")
				if bf, ok := BeeApp.Handlers.filters[AfterExec]; ok {
					for _, f := range bf {
						fmt.Fprintln(rw, f.pattern, utils.GetFuncName(f.filterFunc))
					}
				}
				fmt.Fprintln(rw, "FinishRouter:")
				if bf, ok := BeeApp.Handlers.filters[FinishRouter]; ok {
					for _, f := range bf {
						fmt.Fprintln(rw, f.pattern, utils.GetFuncName(f.filterFunc))
					}
				}
			}
		default:
			rw.Write([]byte("command not support"))
		}
	} else {
		rw.Write([]byte("ListConf support this command:\n"))
		rw.Write([]byte("1. command=conf\n"))
		rw.Write([]byte("2. command=router\n"))
		rw.Write([]byte("3. command=filter\n"))
	}
}
Exemple #3
0
// ListConf is the http.Handler of displaying all beego configuration values as key/value pair.
// it's registered with url pattern "/listconf" in admin module.
func listConf(rw http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	command := r.Form.Get("command")
	if command != "" {
		switch command {
		case "conf":
			fmt.Fprintln(rw, "list all beego's conf:")
			fmt.Fprintln(rw, "AppName:", AppName)
			fmt.Fprintln(rw, "AppPath:", AppPath)
			fmt.Fprintln(rw, "AppConfigPath:", AppConfigPath)
			fmt.Fprintln(rw, "StaticDir:", StaticDir)
			fmt.Fprintln(rw, "StaticExtensionsToGzip:", StaticExtensionsToGzip)
			fmt.Fprintln(rw, "HttpAddr:", HttpAddr)
			fmt.Fprintln(rw, "HttpPort:", HttpPort)
			fmt.Fprintln(rw, "HttpTLS:", EnableHttpTLS)
			fmt.Fprintln(rw, "HttpCertFile:", HttpCertFile)
			fmt.Fprintln(rw, "HttpKeyFile:", HttpKeyFile)
			fmt.Fprintln(rw, "RecoverPanic:", RecoverPanic)
			fmt.Fprintln(rw, "AutoRender:", AutoRender)
			fmt.Fprintln(rw, "ViewsPath:", ViewsPath)
			fmt.Fprintln(rw, "RunMode:", RunMode)
			fmt.Fprintln(rw, "SessionOn:", SessionOn)
			fmt.Fprintln(rw, "SessionProvider:", SessionProvider)
			fmt.Fprintln(rw, "SessionName:", SessionName)
			fmt.Fprintln(rw, "SessionGCMaxLifetime:", SessionGCMaxLifetime)
			fmt.Fprintln(rw, "SessionSavePath:", SessionSavePath)
			fmt.Fprintln(rw, "SessionHashFunc:", SessionHashFunc)
			fmt.Fprintln(rw, "SessionHashKey:", SessionHashKey)
			fmt.Fprintln(rw, "SessionCookieLifeTime:", SessionCookieLifeTime)
			fmt.Fprintln(rw, "UseFcgi:", UseFcgi)
			fmt.Fprintln(rw, "MaxMemory:", MaxMemory)
			fmt.Fprintln(rw, "EnableGzip:", EnableGzip)
			fmt.Fprintln(rw, "DirectoryIndex:", DirectoryIndex)
			fmt.Fprintln(rw, "HttpServerTimeOut:", HttpServerTimeOut)
			fmt.Fprintln(rw, "ErrorsShow:", ErrorsShow)
			fmt.Fprintln(rw, "XSRFKEY:", XSRFKEY)
			fmt.Fprintln(rw, "EnableXSRF:", EnableXSRF)
			fmt.Fprintln(rw, "XSRFExpire:", XSRFExpire)
			fmt.Fprintln(rw, "CopyRequestBody:", CopyRequestBody)
			fmt.Fprintln(rw, "TemplateLeft:", TemplateLeft)
			fmt.Fprintln(rw, "TemplateRight:", TemplateRight)
			fmt.Fprintln(rw, "BeegoServerName:", BeegoServerName)
			fmt.Fprintln(rw, "EnableAdmin:", EnableAdmin)
			fmt.Fprintln(rw, "AdminHttpAddr:", AdminHttpAddr)
			fmt.Fprintln(rw, "AdminHttpPort:", AdminHttpPort)
		case "router":
			fmt.Fprintln(rw, "Print all router infomation:")
			for method, t := range BeeApp.Handlers.routers {
				fmt.Fprintln(rw)
				fmt.Fprintln(rw)
				fmt.Fprintln(rw, "		Method:", method)
				printTree(rw, t)
			}
			// @todo print routers
		case "filter":
			fmt.Fprintln(rw, "Print all filter infomation:")
			if BeeApp.Handlers.enableFilter {
				fmt.Fprintln(rw, "BeforeRouter:")
				if bf, ok := BeeApp.Handlers.filters[BeforeRouter]; ok {
					for _, f := range bf {
						fmt.Fprintln(rw, f.pattern, utils.GetFuncName(f.filterFunc))
					}
				}
				fmt.Fprintln(rw, "BeforeExec:")
				if bf, ok := BeeApp.Handlers.filters[BeforeExec]; ok {
					for _, f := range bf {
						fmt.Fprintln(rw, f.pattern, utils.GetFuncName(f.filterFunc))
					}
				}
				fmt.Fprintln(rw, "AfterExec:")
				if bf, ok := BeeApp.Handlers.filters[AfterExec]; ok {
					for _, f := range bf {
						fmt.Fprintln(rw, f.pattern, utils.GetFuncName(f.filterFunc))
					}
				}
				fmt.Fprintln(rw, "FinishRouter:")
				if bf, ok := BeeApp.Handlers.filters[FinishRouter]; ok {
					for _, f := range bf {
						fmt.Fprintln(rw, f.pattern, utils.GetFuncName(f.filterFunc))
					}
				}
			}
		default:
			rw.Write([]byte("command not support"))
		}
	} else {
		rw.Write([]byte("<html><head><title>beego admin dashboard</title></head><body>"))
		rw.Write([]byte("ListConf support this command:<br>\n"))
		rw.Write([]byte("1. <a href='?command=conf'>command=conf</a><br>\n"))
		rw.Write([]byte("2. <a href='?command=router'>command=router</a><br>\n"))
		rw.Write([]byte("3. <a href='?command=filter'>command=filter</a><br>\n"))
		rw.Write([]byte("</body></html>"))
	}
}
Exemple #4
0
// ListConf is the http.Handler of displaying all beego configuration values as key/value pair.
// it's registered with url pattern "/listconf" in admin module.
func listConf(rw http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	command := r.Form.Get("command")
	if command == "" {
		rw.Write([]byte("command not support"))
		return
	}

	data := make(map[interface{}]interface{})
	switch command {
	case "conf":
		m := make(map[string]interface{})
		m["AppConfigPath"] = appConfigPath
		m["AppConfigProvider"] = appConfigProvider
		m["BConfig.AppName"] = BConfig.AppName
		m["BConfig.RunMode"] = BConfig.RunMode
		m["BConfig.RouterCaseSensitive"] = BConfig.RouterCaseSensitive
		m["BConfig.ServerName"] = BConfig.ServerName
		m["BConfig.RecoverPanic"] = BConfig.RecoverPanic
		m["BConfig.CopyRequestBody"] = BConfig.CopyRequestBody
		m["BConfig.EnableGzip"] = BConfig.EnableGzip
		m["BConfig.MaxMemory"] = BConfig.MaxMemory
		m["BConfig.EnableErrorsShow"] = BConfig.EnableErrorsShow
		m["BConfig.Listen.Graceful"] = BConfig.Listen.Graceful
		m["BConfig.Listen.ServerTimeOut"] = BConfig.Listen.ServerTimeOut
		m["BConfig.Listen.ListenTCP4"] = BConfig.Listen.ListenTCP4
		m["BConfig.Listen.EnableHTTP"] = BConfig.Listen.EnableHTTP
		m["BConfig.Listen.HTTPAddr"] = BConfig.Listen.HTTPAddr
		m["BConfig.Listen.HTTPPort"] = BConfig.Listen.HTTPPort
		m["BConfig.Listen.EnableHTTPS"] = BConfig.Listen.EnableHTTPS
		m["BConfig.Listen.HTTPSAddr"] = BConfig.Listen.HTTPSAddr
		m["BConfig.Listen.HTTPSPort"] = BConfig.Listen.HTTPSPort
		m["BConfig.Listen.HTTPSCertFile"] = BConfig.Listen.HTTPSCertFile
		m["BConfig.Listen.HTTPSKeyFile"] = BConfig.Listen.HTTPSKeyFile
		m["BConfig.Listen.EnableAdmin"] = BConfig.Listen.EnableAdmin
		m["BConfig.Listen.AdminAddr"] = BConfig.Listen.AdminAddr
		m["BConfig.Listen.AdminPort"] = BConfig.Listen.AdminPort
		m["BConfig.Listen.EnableFcgi"] = BConfig.Listen.EnableFcgi
		m["BConfig.Listen.EnableStdIo"] = BConfig.Listen.EnableStdIo
		m["BConfig.WebConfig.AutoRender"] = BConfig.WebConfig.AutoRender
		m["BConfig.WebConfig.EnableDocs"] = BConfig.WebConfig.EnableDocs
		m["BConfig.WebConfig.FlashName"] = BConfig.WebConfig.FlashName
		m["BConfig.WebConfig.FlashSeparator"] = BConfig.WebConfig.FlashSeparator
		m["BConfig.WebConfig.DirectoryIndex"] = BConfig.WebConfig.DirectoryIndex
		m["BConfig.WebConfig.StaticDir"] = BConfig.WebConfig.StaticDir
		m["BConfig.WebConfig.StaticExtensionsToGzip"] = BConfig.WebConfig.StaticExtensionsToGzip
		m["BConfig.WebConfig.TemplateLeft"] = BConfig.WebConfig.TemplateLeft
		m["BConfig.WebConfig.TemplateRight"] = BConfig.WebConfig.TemplateRight
		m["BConfig.WebConfig.ViewsPath"] = BConfig.WebConfig.ViewsPath
		m["BConfig.WebConfig.EnableXSRF"] = BConfig.WebConfig.EnableXSRF
		m["BConfig.WebConfig.XSRFKEY"] = BConfig.WebConfig.XSRFKey
		m["BConfig.WebConfig.XSRFExpire"] = BConfig.WebConfig.XSRFExpire
		m["BConfig.WebConfig.Session.SessionOn"] = BConfig.WebConfig.Session.SessionOn
		m["BConfig.WebConfig.Session.SessionProvider"] = BConfig.WebConfig.Session.SessionProvider
		m["BConfig.WebConfig.Session.SessionName"] = BConfig.WebConfig.Session.SessionName
		m["BConfig.WebConfig.Session.SessionGCMaxLifetime"] = BConfig.WebConfig.Session.SessionGCMaxLifetime
		m["BConfig.WebConfig.Session.SessionProviderConfig"] = BConfig.WebConfig.Session.SessionProviderConfig
		m["BConfig.WebConfig.Session.SessionCookieLifeTime"] = BConfig.WebConfig.Session.SessionCookieLifeTime
		m["BConfig.WebConfig.Session.SessionAutoSetCookie"] = BConfig.WebConfig.Session.SessionAutoSetCookie
		m["BConfig.WebConfig.Session.SessionDomain"] = BConfig.WebConfig.Session.SessionDomain
		m["BConfig.Log.AccessLogs"] = BConfig.Log.AccessLogs
		m["BConfig.Log.FileLineNum"] = BConfig.Log.FileLineNum
		m["BConfig.Log.Outputs"] = BConfig.Log.Outputs
		tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
		tmpl = template.Must(tmpl.Parse(configTpl))
		tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))

		data["Content"] = m

		tmpl.Execute(rw, data)

	case "router":
		var (
			content = map[string]interface{}{
				"Fields": []string{
					"Router Pattern",
					"Methods",
					"Controller",
				},
			}
			methods     = []string{}
			methodsData = make(map[string]interface{})
		)
		for method, t := range BeeApp.Handlers.routers {

			resultList := new([][]string)

			printTree(resultList, t)

			methods = append(methods, method)
			methodsData[method] = resultList
		}

		content["Data"] = methodsData
		content["Methods"] = methods
		data["Content"] = content
		data["Title"] = "Routers"
		execTpl(rw, data, routerAndFilterTpl, defaultScriptsTpl)
	case "filter":
		var (
			content = map[string]interface{}{
				"Fields": []string{
					"Router Pattern",
					"Filter Function",
				},
			}
			filterTypes    = []string{}
			filterTypeData = make(map[string]interface{})
		)

		if BeeApp.Handlers.enableFilter {
			var filterType string
			for k, fr := range map[int]string{
				BeforeStatic: "Before Static",
				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)
					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
				}
			}
		}

		content["Data"] = filterTypeData
		content["Methods"] = filterTypes

		data["Content"] = content
		data["Title"] = "Filters"
		execTpl(rw, data, routerAndFilterTpl, defaultScriptsTpl)
	default:
		rw.Write([]byte("command not support"))
	}
}
Exemple #5
0
// ListConf is the http.Handler of displaying all beego configuration values as key/value pair.
// it's registered with url pattern "/listconf" in admin module.
func listConf(rw http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	command := r.Form.Get("command")
	if command == "" {
		rw.Write([]byte("command not support"))
		return
	}

	data := make(map[interface{}]interface{})
	switch command {
	case "conf":
		m := make(map[string]interface{})
		list("BConfig", BConfig, m)
		m["AppConfigPath"] = appConfigPath
		m["AppConfigProvider"] = appConfigProvider
		tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
		tmpl = template.Must(tmpl.Parse(configTpl))
		tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))

		data["Content"] = m

		tmpl.Execute(rw, data)

	case "router":
		var (
			content = map[string]interface{}{
				"Fields": []string{
					"Router Pattern",
					"Methods",
					"Controller",
				},
			}
			methods     = []string{}
			methodsData = make(map[string]interface{})
		)
		for method, t := range BeeApp.Handlers.routers {

			resultList := new([][]string)

			printTree(resultList, t)

			methods = append(methods, method)
			methodsData[method] = resultList
		}

		content["Data"] = methodsData
		content["Methods"] = methods
		data["Content"] = content
		data["Title"] = "Routers"
		execTpl(rw, data, routerAndFilterTpl, defaultScriptsTpl)
	case "filter":
		var (
			content = map[string]interface{}{
				"Fields": []string{
					"Router Pattern",
					"Filter Function",
				},
			}
			filterTypes    = []string{}
			filterTypeData = make(map[string]interface{})
		)

		if BeeApp.Handlers.enableFilter {
			var filterType string
			for k, fr := range map[int]string{
				BeforeStatic: "Before Static",
				BeforeRouter: "Before Router",
				BeforeExec:   "Before Exec",
				AfterExec:    "After Exec",
				FinishRouter: "Finish Router"} {
				if bf := BeeApp.Handlers.filters[k]; len(bf) > 0 {
					filterType = fr
					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
				}
			}
		}

		content["Data"] = filterTypeData
		content["Methods"] = filterTypes

		data["Content"] = content
		data["Title"] = "Filters"
		execTpl(rw, data, routerAndFilterTpl, defaultScriptsTpl)
	default:
		rw.Write([]byte("command not support"))
	}
}