1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 01:50:53 +00:00
This commit is contained in:
Ming Deng 2020-09-20 15:36:08 +08:00
parent 2473e69417
commit e6a257f987
4 changed files with 23 additions and 23 deletions

View File

@ -46,23 +46,9 @@ var beeAdminApp *adminApp
var FilterMonitorFunc func(string, string, time.Duration, string, int) bool var FilterMonitorFunc func(string, string, time.Duration, string, int) bool
func init() { func init() {
c := &adminController{
servers: make([]*HttpServer, 0, 2),
}
beeAdminApp = &adminApp{
HttpServer: NewHttpServerWithCfg(*BConfig),
}
// keep in mind that all data should be html escaped to avoid XSS attack
beeAdminApp.Router("/", c, "get:AdminIndex")
beeAdminApp.Router("/qps", c, "get:QpsIndex")
beeAdminApp.Router("/prof", c, "get:ProfIndex")
beeAdminApp.Router("/healthcheck", c, "get:Healthcheck")
beeAdminApp.Router("/task", c, "get:TaskStatus")
beeAdminApp.Router("/listconf", c, "get:ListConf")
beeAdminApp.Router("/metrics", c, "get:PrometheusMetrics")
FilterMonitorFunc = func(string, string, time.Duration, string, int) bool { return true } FilterMonitorFunc = func(string, string, time.Duration, string, int) bool { return true }
beeAdminApp.Run()
} }
func list(root string, p interface{}, m M) { func list(root string, p interface{}, m M) {
@ -110,11 +96,28 @@ func (admin *adminApp) Run() {
} }
logs.Info("Admin server Running on %s", addr) logs.Info("Admin server Running on %s", addr)
admin.HttpServer.Run(addr) admin.HttpServer.Run(addr)
} }
func registerAdmin() error { func registerAdmin() error {
if BConfig.Listen.EnableAdmin { if BConfig.Listen.EnableAdmin {
c := &adminController{
servers: make([]*HttpServer, 0, 2),
}
beeAdminApp = &adminApp{
HttpServer: NewHttpServerWithCfg(*BConfig),
}
// keep in mind that all data should be html escaped to avoid XSS attack
beeAdminApp.Router("/", c, "get:AdminIndex")
beeAdminApp.Router("/qps", c, "get:QpsIndex")
beeAdminApp.Router("/prof", c, "get:ProfIndex")
beeAdminApp.Router("/healthcheck", c, "get:Healthcheck")
beeAdminApp.Router("/task", c, "get:TaskStatus")
beeAdminApp.Router("/listconf", c, "get:ListConf")
beeAdminApp.Router("/metrics", c, "get:PrometheusMetrics")
go beeAdminApp.Run() go beeAdminApp.Run()
} }
return nil return nil

View File

@ -41,7 +41,7 @@ type Config struct {
RouterCaseSensitive bool RouterCaseSensitive bool
ServerName string ServerName string
RecoverPanic bool RecoverPanic bool
RecoverFunc func(*context.Context) RecoverFunc func(*context.Context, *Config)
CopyRequestBody bool CopyRequestBody bool
EnableGzip bool EnableGzip bool
MaxMemory int64 MaxMemory int64
@ -169,7 +169,7 @@ func init() {
} }
} }
func (cfg *Config) defaultRecoverPanic(ctx *context.Context) { func defaultRecoverPanic(ctx *context.Context, cfg *Config) {
if err := recover(); err != nil { if err := recover(); err != nil {
if err == ErrAbort { if err == ErrAbort {
return return
@ -281,7 +281,7 @@ func newBConfig() *Config {
}, },
} }
res.RecoverFunc = res.defaultRecoverPanic res.RecoverFunc = defaultRecoverPanic
return res return res
} }

View File

@ -155,6 +155,7 @@ func NewControllerRegisterWithCfg(cfg *Config) *ControllerRegister {
return beecontext.NewContext() return beecontext.NewContext()
}, },
}, },
cfg: cfg,
} }
res.chainRoot = newFilterRouter("/*", res.serveHttp, WithCaseSensitive(false)) res.chainRoot = newFilterRouter("/*", res.serveHttp, WithCaseSensitive(false))
return res return res
@ -678,7 +679,7 @@ func (p *ControllerRegister) serveHttp(ctx *beecontext.Context) {
) )
if p.cfg.RecoverFunc != nil { if p.cfg.RecoverFunc != nil {
defer p.cfg.RecoverFunc(ctx) defer p.cfg.RecoverFunc(ctx, p.cfg)
} }
ctx.Output.EnableGzip = p.cfg.EnableGzip ctx.Output.EnableGzip = p.cfg.EnableGzip

View File

@ -266,10 +266,6 @@ func (app *HttpServer) Run(addr string, mws ...MiddleWare) {
<-endRunning <-endRunning
} }
func (app *HttpServer) Start() {
}
// Router see HttpServer.Router // Router see HttpServer.Router
func Router(rootpath string, c ControllerInterface, mappingMethods ...string) *HttpServer { func Router(rootpath string, c ControllerInterface, mappingMethods ...string) *HttpServer {
return BeeApp.Router(rootpath, c, mappingMethods...) return BeeApp.Router(rootpath, c, mappingMethods...)