File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -49,7 +49,15 @@ type Client struct {
4949 err error
5050}
5151
52- func NewClient (conn net.Conn ) * Client {
52+ type ClientOpts func (c * Client )
53+
54+ func WithOnClose (onClose func ()) ClientOpts {
55+ return func (c * Client ) {
56+ c .closeFunc = onClose
57+ }
58+ }
59+
60+ func NewClient (conn net.Conn , opts ... ClientOpts ) * Client {
5361 c := & Client {
5462 codec : codec {},
5563 conn : conn ,
@@ -60,6 +68,10 @@ func NewClient(conn net.Conn) *Client {
6068 closeFunc : func () {},
6169 }
6270
71+ for _ , o := range opts {
72+ o (c )
73+ }
74+
6375 go c .run ()
6476 return c
6577}
@@ -141,11 +153,6 @@ func (c *Client) Close() error {
141153 return nil
142154}
143155
144- // OnClose allows a close func to be called when the server is closed
145- func (c * Client ) OnClose (closer func ()) {
146- c .closeFunc = closer
147- }
148-
149156type message struct {
150157 messageHeader
151158 p []byte
You can’t perform that action at this time.
0 commit comments