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
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 }
beeAdminApp.Run()
}
func list(root string, p interface{}, m M) {
@ -110,11 +96,28 @@ func (admin *adminApp) Run() {
}
logs.Info("Admin server Running on %s", addr)
admin.HttpServer.Run(addr)
}
func registerAdmin() error {
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()
}
return nil

View File

@ -41,7 +41,7 @@ type Config struct {
RouterCaseSensitive bool
ServerName string
RecoverPanic bool
RecoverFunc func(*context.Context)
RecoverFunc func(*context.Context, *Config)
CopyRequestBody bool
EnableGzip bool
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 == ErrAbort {
return
@ -281,7 +281,7 @@ func newBConfig() *Config {
},
}
res.RecoverFunc = res.defaultRecoverPanic
res.RecoverFunc = defaultRecoverPanic
return res
}

View File

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

View File

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