mirror of
https://github.com/astaxie/beego.git
synced 2024-11-21 16:50:54 +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),
|
||||
}
|
||||
beeAdminApp = &adminApp{
|
||||
HttpServer: NewHttpServerWithCfg(*BConfig),
|
||||
HttpServer: NewHttpServerWithCfg(BConfig),
|
||||
}
|
||||
// keep in mind that all data should be html escaped to avoid XSS attack
|
||||
beeAdminApp.Router("/", c, "get:AdminIndex")
|
||||
|
@ -59,19 +59,18 @@ type HttpServer struct {
|
||||
|
||||
// NewHttpSever returns a new beego application.
|
||||
// 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 {
|
||||
return NewHttpServerWithCfg(*BConfig)
|
||||
return NewHttpServerWithCfg(BConfig)
|
||||
}
|
||||
|
||||
// NewHttpServerWithCfg will create an sever with specific cfg
|
||||
func NewHttpServerWithCfg(cfg Config) *HttpServer {
|
||||
cfgPtr := &cfg
|
||||
cr := NewControllerRegisterWithCfg(cfgPtr)
|
||||
func NewHttpServerWithCfg(cfg *Config) *HttpServer {
|
||||
cr := NewControllerRegisterWithCfg(cfg)
|
||||
app := &HttpServer{
|
||||
Handlers: cr,
|
||||
Server: &http.Server{},
|
||||
Cfg: cfgPtr,
|
||||
Cfg: cfg,
|
||||
}
|
||||
|
||||
return app
|
||||
|
@ -21,11 +21,10 @@ import (
|
||||
)
|
||||
|
||||
func TestNewHttpServerWithCfg(t *testing.T) {
|
||||
// we should make sure that update server's config won't change
|
||||
|
||||
BConfig.AppName = "Before"
|
||||
svr := NewHttpServerWithCfg(*BConfig)
|
||||
svr := NewHttpServerWithCfg(BConfig)
|
||||
svr.Cfg.AppName = "hello"
|
||||
assert.NotEqual(t, "hello", BConfig.AppName)
|
||||
assert.Equal(t, "Before", BConfig.AppName)
|
||||
assert.Equal(t, "hello", BConfig.AppName)
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user