mirror of
https://github.com/astaxie/beego.git
synced 2024-11-21 21:10:55 +00:00
Change NewHttpServer API
This commit is contained in:
parent
03ba495b7f
commit
7c61eb058f
@ -109,7 +109,7 @@ func registerAdmin() error {
|
|||||||
servers: make([]*HttpServer, 0, 2),
|
servers: make([]*HttpServer, 0, 2),
|
||||||
}
|
}
|
||||||
beeAdminApp = &adminApp{
|
beeAdminApp = &adminApp{
|
||||||
HttpServer: NewHttpServerWithCfg(*BConfig),
|
HttpServer: NewHttpServerWithCfg(BConfig),
|
||||||
}
|
}
|
||||||
// keep in mind that all data should be html escaped to avoid XSS attack
|
// keep in mind that all data should be html escaped to avoid XSS attack
|
||||||
beeAdminApp.Router("/", c, "get:AdminIndex")
|
beeAdminApp.Router("/", c, "get:AdminIndex")
|
||||||
|
@ -59,19 +59,18 @@ type HttpServer struct {
|
|||||||
|
|
||||||
// NewHttpSever returns a new beego application.
|
// NewHttpSever returns a new beego application.
|
||||||
// this method will use the BConfig as the configure to create HttpServer
|
// this method will use the BConfig as the configure to create HttpServer
|
||||||
// Be careful that when you update BConfig, the server's Cfg will not be updated
|
// Be careful that when you update BConfig, the server's Cfg will be updated too
|
||||||
func NewHttpSever() *HttpServer {
|
func NewHttpSever() *HttpServer {
|
||||||
return NewHttpServerWithCfg(*BConfig)
|
return NewHttpServerWithCfg(BConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHttpServerWithCfg will create an sever with specific cfg
|
// NewHttpServerWithCfg will create an sever with specific cfg
|
||||||
func NewHttpServerWithCfg(cfg Config) *HttpServer {
|
func NewHttpServerWithCfg(cfg *Config) *HttpServer {
|
||||||
cfgPtr := &cfg
|
cr := NewControllerRegisterWithCfg(cfg)
|
||||||
cr := NewControllerRegisterWithCfg(cfgPtr)
|
|
||||||
app := &HttpServer{
|
app := &HttpServer{
|
||||||
Handlers: cr,
|
Handlers: cr,
|
||||||
Server: &http.Server{},
|
Server: &http.Server{},
|
||||||
Cfg: cfgPtr,
|
Cfg: cfg,
|
||||||
}
|
}
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
@ -21,11 +21,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestNewHttpServerWithCfg(t *testing.T) {
|
func TestNewHttpServerWithCfg(t *testing.T) {
|
||||||
// we should make sure that update server's config won't change
|
|
||||||
BConfig.AppName = "Before"
|
BConfig.AppName = "Before"
|
||||||
svr := NewHttpServerWithCfg(*BConfig)
|
svr := NewHttpServerWithCfg(BConfig)
|
||||||
svr.Cfg.AppName = "hello"
|
svr.Cfg.AppName = "hello"
|
||||||
assert.NotEqual(t, "hello", BConfig.AppName)
|
assert.Equal(t, "hello", BConfig.AppName)
|
||||||
assert.Equal(t, "Before", BConfig.AppName)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user