forked from aceld/zinx
/
options.go
34 lines (28 loc) · 908 Bytes
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package znet
import "github.com/iaoizo/zinx/ziface"
// Options for Server
// (Server的服务Option)
type Option func(s *Server)
// Implement custom data packet format by implementing the Packet interface,
// otherwise use the default data packet format
// (只要实现Packet 接口可自由实现数据包解析格式,如果没有则使用默认解析格式)
func WithPacket(pack ziface.IDataPack) Option {
return func(s *Server) {
s.SetPacket(pack)
}
}
// Options for Client
type ClientOption func(c ziface.IClient)
// Implement custom data packet format by implementing the Packet interface for client,
// otherwise use the default data packet format
func WithPacketClient(pack ziface.IDataPack) ClientOption {
return func(c ziface.IClient) {
c.SetPacket(pack)
}
}
// Set client name
func WithNameClient(name string) ClientOption {
return func(c ziface.IClient) {
c.SetName(name)
}
}