tcpmachine/tcpserver/options.go
2024-10-19 22:55:35 +03:00

40 lines
1.0 KiB
Go

package tcpserver
import "net"
type ServerOption func(conf *ServerConfiguration)
// WithMessageEndRune sets the MessageEndRune in the server configuration.
func WithMessageEndRune(r rune) ServerOption {
return func(conf *ServerConfiguration) {
conf.MessageEndRune = r
}
}
// WithMessageSplitRune sets the MessageSplitRune in the server configuration.
func WithMessageSplitRune(r rune) ServerOption {
return func(conf *ServerConfiguration) {
conf.MessageSplitRune = r
}
}
// WithErrorResolver sets a custom error resolver function.
func WithErrorResolver(resolver func(chan error)) ServerOption {
return func(conf *ServerConfiguration) {
conf.ErrorResolver = resolver
}
}
// WithHandleClientFunc sets the HandleClientFunc in the server configuration.
func WithHandleClientFunc(handler func(client net.Conn)) ServerOption {
return func(conf *ServerConfiguration) {
conf.HandleClientFunc = handler
}
}
func WithLoggingLevel(level ServerLoggingLevel) ServerOption {
return func(conf *ServerConfiguration) {
conf.LogLevel = level
}
}