Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如果在同一台服务器初始化了两个server,初始化服务器顺序不同,导致routerslice问题 #288

Open
trash-boy opened this issue Dec 13, 2023 · 1 comment

Comments

@trash-boy
Copy link
Contributor

在初始化服务器的时候,如果在同一台服务器初始化了两个server,例如下所示,

func TestTwoServer(t *testing.T){
fmt.Println("server Test")
_ = NewServer()
t.Log(zconf.GlobalObject)
_ = NewDefaultRouterSlicesServer()
t.Log(zconf.GlobalObject)
}

第一个server的routerslice为false,第二个server为true
可是如果调换了顺序

func TestTwoServerReversed(t *testing.T){
fmt.Println("server Test")
_ = NewDefaultRouterSlicesServer()
t.Log(zconf.GlobalObject)
_ = NewServer()
t.Log(zconf.GlobalObject)
}
两个都为true,不符合初始化的想法,主要原因是,server.go的148行代码,zconf.GlobalObject是一个指针变量

func NewDefaultRouterSlicesServer(opts ...Option) ziface.IServer {
zconf.GlobalObject.RouterSlicesMode = true
s := newServerWithConfig(zconf.GlobalObject, "tcp", opts...)
s.Use(RouterRecovery)
return s
}

@aceld
Copy link
Owner

aceld commented Dec 14, 2023

目前暂时不支持这种写法,不过全局一个Config 这块确实应该改进下,改成Config是一个Server的属性。这块在等待有人提PR,或者今后改进。这个问题就不存在了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants