tcpmachine/tcpclient/options.go

24 lines
502 B
Go
Raw Permalink Normal View History

2024-10-12 11:34:47 +02:00
package tcpclient
import "net"
2024-10-12 11:34:47 +02:00
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
}
}
func WithServerHandler(fun func(server net.Conn)) ClientOption {
return func(conf *ClientConfiguration) {
conf.ServerHandlerFunc = fun
}
}