1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 03:01:00 +00:00

beego: BeeAdminApp private

This commit is contained in:
astaxie 2014-04-06 01:02:10 +08:00
parent 3ad30d48b5
commit 5a863b45f4
2 changed files with 24 additions and 24 deletions

View File

@ -9,8 +9,8 @@ import (
"github.com/astaxie/beego/utils" "github.com/astaxie/beego/utils"
) )
// BeeAdminApp is the default AdminApp used by admin module. // BeeAdminApp is the default adminApp used by admin module.
var BeeAdminApp *AdminApp var beeAdminApp *adminApp
// FilterMonitorFunc is default monitor filter when admin module is enable. // FilterMonitorFunc is default monitor filter when admin module is enable.
// if this func returns, admin module records qbs for this request by condition of this function logic. // if this func returns, admin module records qbs for this request by condition of this function logic.
@ -31,22 +31,22 @@ var BeeAdminApp *AdminApp
var FilterMonitorFunc func(string, string, time.Duration) bool var FilterMonitorFunc func(string, string, time.Duration) bool
func init() { func init() {
BeeAdminApp = &AdminApp{ beeAdminApp = &adminApp{
routers: make(map[string]http.HandlerFunc), routers: make(map[string]http.HandlerFunc),
} }
BeeAdminApp.Route("/", AdminIndex) beeAdminApp.Route("/", adminIndex)
BeeAdminApp.Route("/qps", QpsIndex) beeAdminApp.Route("/qps", qpsIndex)
BeeAdminApp.Route("/prof", ProfIndex) beeAdminApp.Route("/prof", profIndex)
BeeAdminApp.Route("/healthcheck", Healthcheck) beeAdminApp.Route("/healthcheck", healthcheck)
BeeAdminApp.Route("/task", TaskStatus) beeAdminApp.Route("/task", taskStatus)
BeeAdminApp.Route("/runtask", RunTask) beeAdminApp.Route("/runtask", runTask)
BeeAdminApp.Route("/listconf", ListConf) beeAdminApp.Route("/listconf", listConf)
FilterMonitorFunc = func(string, string, time.Duration) bool { return true } FilterMonitorFunc = func(string, string, time.Duration) bool { return true }
} }
// 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) {
rw.Write([]byte("Welcome to Admin Dashboard\n")) rw.Write([]byte("Welcome to Admin Dashboard\n"))
rw.Write([]byte("There are servral functions:\n")) rw.Write([]byte("There are servral functions:\n"))
rw.Write([]byte("1. Record all request and request time, http://localhost:8088/qps\n")) rw.Write([]byte("1. Record all request and request time, http://localhost:8088/qps\n"))
@ -60,13 +60,13 @@ func AdminIndex(rw http.ResponseWriter, r *http.Request) {
// 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) {
toolbox.StatisticsMap.GetMap(rw) toolbox.StatisticsMap.GetMap(rw)
} }
// 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.
// it's registered with url pattern "/listconf" in admin module. // it's registered with url pattern "/listconf" in admin module.
func ListConf(rw http.ResponseWriter, r *http.Request) { func listConf(rw http.ResponseWriter, r *http.Request) {
r.ParseForm() r.ParseForm()
command := r.Form.Get("command") command := r.Form.Get("command")
if command != "" { if command != "" {
@ -183,7 +183,7 @@ func ListConf(rw http.ResponseWriter, r *http.Request) {
// ProfIndex is a http.Handler for showing profile command. // ProfIndex is a http.Handler for showing profile command.
// it's in url pattern "/prof" in admin module. // it's in url pattern "/prof" in admin module.
func ProfIndex(rw http.ResponseWriter, r *http.Request) { func profIndex(rw http.ResponseWriter, r *http.Request) {
r.ParseForm() r.ParseForm()
command := r.Form.Get("command") command := r.Form.Get("command")
if command != "" { if command != "" {
@ -204,7 +204,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, req *http.Request) { func healthcheck(rw http.ResponseWriter, req *http.Request) {
for name, h := range toolbox.AdminCheckList { for name, h := range toolbox.AdminCheckList {
if err := h.Check(); err != nil { if err := h.Check(); err != nil {
fmt.Fprintf(rw, "%s : ok\n", name) fmt.Fprintf(rw, "%s : ok\n", name)
@ -216,7 +216,7 @@ func Healthcheck(rw http.ResponseWriter, req *http.Request) {
// 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) {
for tname, tk := range toolbox.AdminTaskList { for tname, tk := range toolbox.AdminTaskList {
fmt.Fprintf(rw, "%s:%s:%s", tname, tk.GetStatus(), tk.GetPrev().String()) fmt.Fprintf(rw, "%s:%s:%s", tname, tk.GetStatus(), tk.GetPrev().String())
} }
@ -224,7 +224,7 @@ func TaskStatus(rw http.ResponseWriter, req *http.Request) {
// RunTask is a http.Handler to run a Task from the "query string. // RunTask is a http.Handler to run a Task from the "query string.
// the request url likes /runtask?taskname=sendmail. // the request url likes /runtask?taskname=sendmail.
func RunTask(rw http.ResponseWriter, req *http.Request) { func runTask(rw http.ResponseWriter, req *http.Request) {
req.ParseForm() req.ParseForm()
taskname := req.Form.Get("taskname") taskname := req.Form.Get("taskname")
if t, ok := toolbox.AdminTaskList[taskname]; ok { if t, ok := toolbox.AdminTaskList[taskname]; ok {
@ -238,19 +238,19 @@ func RunTask(rw http.ResponseWriter, req *http.Request) {
} }
} }
// AdminApp is an http.HandlerFunc map used as BeeAdminApp. // adminApp is an http.HandlerFunc map used as beeAdminApp.
type AdminApp struct { type adminApp struct {
routers map[string]http.HandlerFunc routers map[string]http.HandlerFunc
} }
// Route adds http.HandlerFunc to AdminApp with url pattern. // Route adds http.HandlerFunc to adminApp with url pattern.
func (admin *AdminApp) Route(pattern string, f http.HandlerFunc) { func (admin *adminApp) Route(pattern string, f http.HandlerFunc) {
admin.routers[pattern] = f admin.routers[pattern] = f
} }
// Run AdminApp http server. // Run adminApp http server.
// Its addr is defined in configuration file as adminhttpaddr and adminhttpport. // Its addr is defined in configuration file as adminhttpaddr and adminhttpport.
func (admin *AdminApp) Run() { func (admin *adminApp) Run() {
if len(toolbox.AdminTaskList) > 0 { if len(toolbox.AdminTaskList) > 0 {
toolbox.StartTask() toolbox.StartTask()
} }

View File

@ -179,7 +179,7 @@ func Run() {
initBeforeHttpRun() initBeforeHttpRun()
if EnableAdmin { if EnableAdmin {
go BeeAdminApp.Run() go beeAdminApp.Run()
} }
BeeApp.Run() BeeApp.Run()