add api comments in file admin.go
Showing
1 changed file
with
25 additions
and
6 deletions
| ... | @@ -9,9 +9,13 @@ import ( | ... | @@ -9,9 +9,13 @@ 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 | var BeeAdminApp *AdminApp | 13 | var BeeAdminApp *AdminApp |
| 13 | 14 | ||
| 14 | //func MyFilterMonitor(method, requestPath string, t time.Duration) bool { | 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. | ||
| 17 | // usage: | ||
| 18 | // func MyFilterMonitor(method, requestPath string, t time.Duration) bool { | ||
| 15 | // if method == "POST" { | 19 | // if method == "POST" { |
| 16 | // return false | 20 | // return false |
| 17 | // } | 21 | // } |
| ... | @@ -22,9 +26,8 @@ var BeeAdminApp *AdminApp | ... | @@ -22,9 +26,8 @@ var BeeAdminApp *AdminApp |
| 22 | // return false | 26 | // return false |
| 23 | // } | 27 | // } |
| 24 | // return true | 28 | // return true |
| 25 | //} | 29 | // } |
| 26 | 30 | // beego.FilterMonitorFunc = MyFilterMonitor. | |
| 27 | //beego.FilterMonitorFunc = MyFilterMonitor | ||
| 28 | var FilterMonitorFunc func(string, string, time.Duration) bool | 31 | var FilterMonitorFunc func(string, string, time.Duration) bool |
| 29 | 32 | ||
| 30 | func init() { | 33 | func init() { |
| ... | @@ -41,6 +44,8 @@ func init() { | ... | @@ -41,6 +44,8 @@ func init() { |
| 41 | FilterMonitorFunc = func(string, string, time.Duration) bool { return true } | 44 | FilterMonitorFunc = func(string, string, time.Duration) bool { return true } |
| 42 | } | 45 | } |
| 43 | 46 | ||
| 47 | // AdminIndex is the default http.Handler for admin module. | ||
| 48 | // it matches url pattern "/". | ||
| 44 | func AdminIndex(rw http.ResponseWriter, r *http.Request) { | 49 | func AdminIndex(rw http.ResponseWriter, r *http.Request) { |
| 45 | rw.Write([]byte("Welcome to Admin Dashboard\n")) | 50 | rw.Write([]byte("Welcome to Admin Dashboard\n")) |
| 46 | rw.Write([]byte("There are servral functions:\n")) | 51 | rw.Write([]byte("There are servral functions:\n")) |
| ... | @@ -53,10 +58,14 @@ func AdminIndex(rw http.ResponseWriter, r *http.Request) { | ... | @@ -53,10 +58,14 @@ func AdminIndex(rw http.ResponseWriter, r *http.Request) { |
| 53 | 58 | ||
| 54 | } | 59 | } |
| 55 | 60 | ||
| 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. | ||
| 56 | func QpsIndex(rw http.ResponseWriter, r *http.Request) { | 63 | func QpsIndex(rw http.ResponseWriter, r *http.Request) { |
| 57 | toolbox.StatisticsMap.GetMap(rw) | 64 | toolbox.StatisticsMap.GetMap(rw) |
| 58 | } | 65 | } |
| 59 | 66 | ||
| 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. | ||
| 60 | func ListConf(rw http.ResponseWriter, r *http.Request) { | 69 | func ListConf(rw http.ResponseWriter, r *http.Request) { |
| 61 | r.ParseForm() | 70 | r.ParseForm() |
| 62 | command := r.Form.Get("command") | 71 | command := r.Form.Get("command") |
| ... | @@ -172,6 +181,8 @@ func ListConf(rw http.ResponseWriter, r *http.Request) { | ... | @@ -172,6 +181,8 @@ func ListConf(rw http.ResponseWriter, r *http.Request) { |
| 172 | } | 181 | } |
| 173 | } | 182 | } |
| 174 | 183 | ||
| 184 | // ProfIndex is a http.Handler for showing profile command. | ||
| 185 | // it's in url pattern "/prof" in admin module. | ||
| 175 | func ProfIndex(rw http.ResponseWriter, r *http.Request) { | 186 | func ProfIndex(rw http.ResponseWriter, r *http.Request) { |
| 176 | r.ParseForm() | 187 | r.ParseForm() |
| 177 | command := r.Form.Get("command") | 188 | command := r.Form.Get("command") |
| ... | @@ -191,6 +202,8 @@ func ProfIndex(rw http.ResponseWriter, r *http.Request) { | ... | @@ -191,6 +202,8 @@ func ProfIndex(rw http.ResponseWriter, r *http.Request) { |
| 191 | } | 202 | } |
| 192 | } | 203 | } |
| 193 | 204 | ||
| 205 | // Healthcheck is a http.Handler calling health checking and showing the result. | ||
| 206 | // it's in "/healthcheck" pattern in admin module. | ||
| 194 | func Healthcheck(rw http.ResponseWriter, req *http.Request) { | 207 | func Healthcheck(rw http.ResponseWriter, req *http.Request) { |
| 195 | for name, h := range toolbox.AdminCheckList { | 208 | for name, h := range toolbox.AdminCheckList { |
| 196 | if err := h.Check(); err != nil { | 209 | if err := h.Check(); err != nil { |
| ... | @@ -201,14 +214,16 @@ func Healthcheck(rw http.ResponseWriter, req *http.Request) { | ... | @@ -201,14 +214,16 @@ func Healthcheck(rw http.ResponseWriter, req *http.Request) { |
| 201 | } | 214 | } |
| 202 | } | 215 | } |
| 203 | 216 | ||
| 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. | ||
| 204 | func TaskStatus(rw http.ResponseWriter, req *http.Request) { | 219 | func TaskStatus(rw http.ResponseWriter, req *http.Request) { |
| 205 | for tname, tk := range toolbox.AdminTaskList { | 220 | for tname, tk := range toolbox.AdminTaskList { |
| 206 | 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()) |
| 207 | } | 222 | } |
| 208 | } | 223 | } |
| 209 | 224 | ||
| 210 | //to run a Task by http from the querystring taskname | 225 | // RunTask is a http.Handler to run a Task from the "query string. |
| 211 | //url like /task?taskname=sendmail | 226 | // the request url likes /runtask?taskname=sendmail. |
| 212 | func RunTask(rw http.ResponseWriter, req *http.Request) { | 227 | func RunTask(rw http.ResponseWriter, req *http.Request) { |
| 213 | req.ParseForm() | 228 | req.ParseForm() |
| 214 | taskname := req.Form.Get("taskname") | 229 | taskname := req.Form.Get("taskname") |
| ... | @@ -223,14 +238,18 @@ func RunTask(rw http.ResponseWriter, req *http.Request) { | ... | @@ -223,14 +238,18 @@ func RunTask(rw http.ResponseWriter, req *http.Request) { |
| 223 | } | 238 | } |
| 224 | } | 239 | } |
| 225 | 240 | ||
| 241 | // AdminApp is an http.HandlerFunc map used as BeeAdminApp. | ||
| 226 | type AdminApp struct { | 242 | type AdminApp struct { |
| 227 | routers map[string]http.HandlerFunc | 243 | routers map[string]http.HandlerFunc |
| 228 | } | 244 | } |
| 229 | 245 | ||
| 246 | // Route adds http.HandlerFunc to AdminApp with url pattern. | ||
| 230 | func (admin *AdminApp) Route(pattern string, f http.HandlerFunc) { | 247 | func (admin *AdminApp) Route(pattern string, f http.HandlerFunc) { |
| 231 | admin.routers[pattern] = f | 248 | admin.routers[pattern] = f |
| 232 | } | 249 | } |
| 233 | 250 | ||
| 251 | // Run AdminApp http server. | ||
| 252 | // Its addr is defined in configuration file as adminhttpaddr and adminhttpport. | ||
| 234 | func (admin *AdminApp) Run() { | 253 | func (admin *AdminApp) Run() { |
| 235 | if len(toolbox.AdminTaskList) > 0 { | 254 | if len(toolbox.AdminTaskList) > 0 { |
| 236 | toolbox.StartTask() | 255 | toolbox.StartTask() | ... | ... |
-
Please register or sign in to post a comment