tcpmachine/tcpserver/options.go

40 lines
1.0 KiB
Go
Raw Normal View History

2024-10-11 08:24:32 +02:00
package tcpserver
import "net"
2024-10-19 21:55:35 +02:00
type ServerOption func(conf *ServerConfiguration)
2024-10-11 08:24:32 +02:00
// 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
}
}
2024-10-19 21:55:35 +02:00
func WithLoggingLevel(level ServerLoggingLevel) ServerOption {
return func(conf *ServerConfiguration) {
conf.LogLevel = level
}
}