aceld / aceld/zinx

服务器配置应该拎出来,改为注入

Đang mở
#98 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Go
Star
7.8k
Fork
1.3k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

```
//NewServer 创建一个服务器句柄
func NewServer() ziface.IServer {
printLogo()

s := &Server{
Name: utils.GlobalObject.Name,
IPVersion: "tcp4",
IP: utils.GlobalObject.Host,
Port: utils.GlobalObject.TCPPort,
msgHandler: NewMsgHandle(),
ConnMgr: NewConnManager(),
}
return s
}
```
### 可以改成类似如下的方式吗?
```

type ZConfig struct {
/*
Server
*/
Name string
TcpVersion string
Ip: string
Port int

/*
Zinx
*/
MaxPacketSize uint32 //都需数据包的最大值
MaxConn int //当前服务器主机允许的最大链接个数
WorkerPoolSize uint32 //业务工作Worker池的数量
MaxWorkerTaskLen uint32 //业务工作Worker对应负责的任务队列最大任务存储数量
MaxMsgChanLen uint32 //SendBuffMsg发送消息的缓冲最大长度

}

//iServer 接口实现,定义一个Server服务类
type Server struct {
//服务器配置
Config ZConfig

......
}
/*
创建一个服务器句柄
*/
func NewServer(conf *ZConfig) ziface.IServer {
printLogo()

s := &Server{
Config: conf,
Name: conf.Name,
IPVersion: conf.TcpVersion,
IP: conf.Ip,
Port: conf.Port,
msgHandler: NewMsgHandle(),
ConnMgr: NewConnManager(),
}
return s
}
```
### 更加方便外部配置.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.