Add Options for CreateClient func

This commit is contained in:
qowevisa 2024-10-12 12:34:47 +03:00
parent 374e3984ce
commit 6bb8dc19b1
2 changed files with 17 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
) )
type ClientConfiguration struct { type ClientConfiguration struct {
Status uint32
ErrorResolver func(chan error) ErrorResolver func(chan error)
} }
@ -26,6 +27,7 @@ type ErrorResolverFunc func(errors chan error)
type Client struct { type Client struct {
addr string addr string
Status uint32
exit chan bool exit chan bool
Server net.Conn Server net.Conn
IsConnected bool IsConnected bool

15
tcpclient/options.go Normal file
View File

@ -0,0 +1,15 @@
package tcpclient
type ClientOption func(conf *ClientConfiguration)
const (
statusBitNothing = 0
statusBitCustomErrorHandling = 1 << iota
)
func WithCustomErrorHandling(fun ErrorResolverFunc) ClientOption {
return func(conf *ClientConfiguration) {
conf.Status |= statusBitCustomErrorHandling
conf.ErrorResolver = fun
}
}