5a863b45 by astaxie

beego: BeeAdminApp private

1 parent 3ad30d48
...@@ -9,8 +9,8 @@ import ( ...@@ -9,8 +9,8 @@ import (
9 "github.com/astaxie/beego/utils" 9 "github.com/astaxie/beego/utils"
10 ) 10 )
11 11
12 // BeeAdminApp is the default AdminApp used by admin module. 12 // BeeAdminApp is the default adminApp used by admin module.
13 var BeeAdminApp *AdminApp 13 var beeAdminApp *adminApp
14 14
15 // FilterMonitorFunc is default monitor filter when admin module is enable. 15 // FilterMonitorFunc is default monitor filter when admin module is enable.
16 // if this func returns, admin module records qbs for this request by condition of this function logic. 16 // if this func returns, admin module records qbs for this request by condition of this function logic.
...@@ -31,22 +31,22 @@ var BeeAdminApp *AdminApp ...@@ -31,22 +31,22 @@ var BeeAdminApp *AdminApp
31 var FilterMonitorFunc func(string, string, time.Duration) bool 31 var FilterMonitorFunc func(string, string, time.Duration) bool
32 32
33 func init() { 33 func init() {
34 BeeAdminApp = &AdminApp{ 34 beeAdminApp = &adminApp{
35 routers: make(map[string]http.HandlerFunc), 35 routers: make(map[string]http.HandlerFunc),
36 } 36 }
37 BeeAdminApp.Route("/", AdminIndex) 37 beeAdminApp.Route("/", adminIndex)
38 BeeAdminApp.Route("/qps", QpsIndex) 38 beeAdminApp.Route("/qps", qpsIndex)
39 BeeAdminApp.Route("/prof", ProfIndex) 39 beeAdminApp.Route("/prof", profIndex)
40 BeeAdminApp.Route("/healthcheck", Healthcheck) 40 beeAdminApp.Route("/healthcheck", healthcheck)
41 BeeAdminApp.Route("/task", TaskStatus) 41 beeAdminApp.Route("/task", taskStatus)
42 BeeAdminApp.Route("/runtask", RunTask) 42 beeAdminApp.Route("/runtask", runTask)
43 BeeAdminApp.Route("/listconf", ListConf) 43 beeAdminApp.Route("/listconf", listConf)
44 FilterMonitorFunc = func(string, string, time.Duration) bool { return true } 44 FilterMonitorFunc = func(string, string, time.Duration) bool { return true }
45 } 45 }
46 46
47 // AdminIndex is the default http.Handler for admin module. 47 // AdminIndex is the default http.Handler for admin module.
48 // it matches url pattern "/". 48 // it matches url pattern "/".
49 func AdminIndex(rw http.ResponseWriter, r *http.Request) { 49 func adminIndex(rw http.ResponseWriter, r *http.Request) {
50 rw.Write([]byte("Welcome to Admin Dashboard\n")) 50 rw.Write([]byte("Welcome to Admin Dashboard\n"))
51 rw.Write([]byte("There are servral functions:\n")) 51 rw.Write([]byte("There are servral functions:\n"))
52 rw.Write([]byte("1. Record all request and request time, http://localhost:8088/qps\n")) 52 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) { ...@@ -60,13 +60,13 @@ func AdminIndex(rw http.ResponseWriter, r *http.Request) {
60 60
61 // QpsIndex is the http.Handler for writing qbs statistics map result info in http.ResponseWriter. 61 // QpsIndex is the http.Handler for writing qbs statistics map result info in http.ResponseWriter.
62 // it's registered with url pattern "/qbs" in admin module. 62 // it's registered with url pattern "/qbs" in admin module.
63 func QpsIndex(rw http.ResponseWriter, r *http.Request) { 63 func qpsIndex(rw http.ResponseWriter, r *http.Request) {
64 toolbox.StatisticsMap.GetMap(rw) 64 toolbox.StatisticsMap.GetMap(rw)
65 } 65 }
66 66
67 // ListConf is the http.Handler of displaying all beego configuration values as key/value pair. 67 // ListConf is the http.Handler of displaying all beego configuration values as key/value pair.
68 // it's registered with url pattern "/listconf" in admin module. 68 // it's registered with url pattern "/listconf" in admin module.
69 func ListConf(rw http.ResponseWriter, r *http.Request) { 69 func listConf(rw http.ResponseWriter, r *http.Request) {
70 r.ParseForm() 70 r.ParseForm()
71 command := r.Form.Get("command") 71 command := r.Form.Get("command")
72 if command != "" { 72 if command != "" {
...@@ -183,7 +183,7 @@ func ListConf(rw http.ResponseWriter, r *http.Request) { ...@@ -183,7 +183,7 @@ func ListConf(rw http.ResponseWriter, r *http.Request) {
183 183
184 // ProfIndex is a http.Handler for showing profile command. 184 // ProfIndex is a http.Handler for showing profile command.
185 // it's in url pattern "/prof" in admin module. 185 // it's in url pattern "/prof" in admin module.
186 func ProfIndex(rw http.ResponseWriter, r *http.Request) { 186 func profIndex(rw http.ResponseWriter, r *http.Request) {
187 r.ParseForm() 187 r.ParseForm()
188 command := r.Form.Get("command") 188 command := r.Form.Get("command")
189 if command != "" { 189 if command != "" {
...@@ -204,7 +204,7 @@ func ProfIndex(rw http.ResponseWriter, r *http.Request) { ...@@ -204,7 +204,7 @@ func ProfIndex(rw http.ResponseWriter, r *http.Request) {
204 204
205 // Healthcheck is a http.Handler calling health checking and showing the result. 205 // Healthcheck is a http.Handler calling health checking and showing the result.
206 // it's in "/healthcheck" pattern in admin module. 206 // it's in "/healthcheck" pattern in admin module.
207 func Healthcheck(rw http.ResponseWriter, req *http.Request) { 207 func healthcheck(rw http.ResponseWriter, req *http.Request) {
208 for name, h := range toolbox.AdminCheckList { 208 for name, h := range toolbox.AdminCheckList {
209 if err := h.Check(); err != nil { 209 if err := h.Check(); err != nil {
210 fmt.Fprintf(rw, "%s : ok\n", name) 210 fmt.Fprintf(rw, "%s : ok\n", name)
...@@ -216,7 +216,7 @@ func Healthcheck(rw http.ResponseWriter, req *http.Request) { ...@@ -216,7 +216,7 @@ func Healthcheck(rw http.ResponseWriter, req *http.Request) {
216 216
217 // TaskStatus is a http.Handler with running task status (task name, status and the last execution). 217 // TaskStatus is a http.Handler with running task status (task name, status and the last execution).
218 // it's in "/task" pattern in admin module. 218 // it's in "/task" pattern in admin module.
219 func TaskStatus(rw http.ResponseWriter, req *http.Request) { 219 func taskStatus(rw http.ResponseWriter, req *http.Request) {
220 for tname, tk := range toolbox.AdminTaskList { 220 for tname, tk := range toolbox.AdminTaskList {
221 fmt.Fprintf(rw, "%s:%s:%s", tname, tk.GetStatus(), tk.GetPrev().String()) 221 fmt.Fprintf(rw, "%s:%s:%s", tname, tk.GetStatus(), tk.GetPrev().String())
222 } 222 }
...@@ -224,7 +224,7 @@ func TaskStatus(rw http.ResponseWriter, req *http.Request) { ...@@ -224,7 +224,7 @@ func TaskStatus(rw http.ResponseWriter, req *http.Request) {
224 224
225 // RunTask is a http.Handler to run a Task from the "query string. 225 // RunTask is a http.Handler to run a Task from the "query string.
226 // the request url likes /runtask?taskname=sendmail. 226 // the request url likes /runtask?taskname=sendmail.
227 func RunTask(rw http.ResponseWriter, req *http.Request) { 227 func runTask(rw http.ResponseWriter, req *http.Request) {
228 req.ParseForm() 228 req.ParseForm()
229 taskname := req.Form.Get("taskname") 229 taskname := req.Form.Get("taskname")
230 if t, ok := toolbox.AdminTaskList[taskname]; ok { 230 if t, ok := toolbox.AdminTaskList[taskname]; ok {
...@@ -238,19 +238,19 @@ func RunTask(rw http.ResponseWriter, req *http.Request) { ...@@ -238,19 +238,19 @@ func RunTask(rw http.ResponseWriter, req *http.Request) {
238 } 238 }
239 } 239 }
240 240
241 // AdminApp is an http.HandlerFunc map used as BeeAdminApp. 241 // adminApp is an http.HandlerFunc map used as beeAdminApp.
242 type AdminApp struct { 242 type adminApp struct {
243 routers map[string]http.HandlerFunc 243 routers map[string]http.HandlerFunc
244 } 244 }
245 245
246 // Route adds http.HandlerFunc to AdminApp with url pattern. 246 // Route adds http.HandlerFunc to adminApp with url pattern.
247 func (admin *AdminApp) Route(pattern string, f http.HandlerFunc) { 247 func (admin *adminApp) Route(pattern string, f http.HandlerFunc) {
248 admin.routers[pattern] = f 248 admin.routers[pattern] = f
249 } 249 }
250 250
251 // Run AdminApp http server. 251 // Run adminApp http server.
252 // Its addr is defined in configuration file as adminhttpaddr and adminhttpport. 252 // Its addr is defined in configuration file as adminhttpaddr and adminhttpport.
253 func (admin *AdminApp) Run() { 253 func (admin *adminApp) Run() {
254 if len(toolbox.AdminTaskList) > 0 { 254 if len(toolbox.AdminTaskList) > 0 {
255 toolbox.StartTask() 255 toolbox.StartTask()
256 } 256 }
......
...@@ -179,7 +179,7 @@ func Run() { ...@@ -179,7 +179,7 @@ func Run() {
179 initBeforeHttpRun() 179 initBeforeHttpRun()
180 180
181 if EnableAdmin { 181 if EnableAdmin {
182 go BeeAdminApp.Run() 182 go beeAdminApp.Run()
183 } 183 }
184 184
185 BeeApp.Run() 185 BeeApp.Run()
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!