Move all types in tcpserver to types.go

This commit is contained in:
qowevisa 2024-10-23 12:39:37 +03:00
parent 6e244be880
commit ecb6e12425
2 changed files with 36 additions and 29 deletions

View File

@ -12,8 +12,6 @@ import (
"git.qowevisa.me/Qowevisa/tcpmachine/tcpcommand" "git.qowevisa.me/Qowevisa/tcpmachine/tcpcommand"
) )
type ServerLoggingLevel int
const ( const (
LogLevel_Nothing = 0 LogLevel_Nothing = 0
LogLevel_Connection = 1 << iota LogLevel_Connection = 1 << iota
@ -24,15 +22,6 @@ const (
LogLevel_ALL = LogLevel_Connection | LogLevel_Messages LogLevel_ALL = LogLevel_Connection | LogLevel_Messages
) )
type ServerConfiguration struct {
MessageEndRune rune
MessageSplitRune rune
HandleClientFunc func(client net.Conn)
LogLevel ServerLoggingLevel
//
ErrorResolver func(chan error)
}
func CreateHandleClientFuncFromCommands(bundle *tcpcommand.CommandBundle, conf ServerConfiguration) (func(client net.Conn), chan error) { func CreateHandleClientFuncFromCommands(bundle *tcpcommand.CommandBundle, conf ServerConfiguration) (func(client net.Conn), chan error) {
clientErrors := make(chan error, 16) clientErrors := make(chan error, 16)
return func(client net.Conn) { return func(client net.Conn) {
@ -58,24 +47,6 @@ func CreateHandleClientFuncFromCommands(bundle *tcpcommand.CommandBundle, conf S
}, clientErrors }, clientErrors
} }
type Server struct {
addr string
PreHandlerClientFunc func(client net.Conn)
HandleClientFunc func(client net.Conn)
// Use PostHandlerClientFunc in your HandleClientFunc if you
// use custom HandleClientFunc
PostHandlerClientFunc func(client net.Conn)
Exit chan bool
//
MessageEndRune rune
MessageSplitRune rune
ErrorsChannel chan error
ErrorResolver func(chan error)
LogLevel ServerLoggingLevel
//
Commands []tcpcommand.Command
}
func defaultHandleClientFunc(server *Server) func(net.Conn) { func defaultHandleClientFunc(server *Server) func(net.Conn) {
return func(client net.Conn) { return func(client net.Conn) {
if server.PostHandlerClientFunc != nil { if server.PostHandlerClientFunc != nil {

36
tcpserver/types.go Normal file
View File

@ -0,0 +1,36 @@
package tcpserver
import (
"net"
"git.qowevisa.me/Qowevisa/tcpmachine/tcpcommand"
)
type ServerLoggingLevel int
type ServerConfiguration struct {
MessageEndRune rune
MessageSplitRune rune
HandleClientFunc func(client net.Conn)
LogLevel ServerLoggingLevel
//
ErrorResolver func(chan error)
}
type Server struct {
addr string
PreHandlerClientFunc func(client net.Conn)
HandleClientFunc func(client net.Conn)
// Use PostHandlerClientFunc in your HandleClientFunc if you
// use custom HandleClientFunc
PostHandlerClientFunc func(client net.Conn)
Exit chan bool
//
MessageEndRune rune
MessageSplitRune rune
ErrorsChannel chan error
ErrorResolver func(chan error)
LogLevel ServerLoggingLevel
//
Commands []tcpcommand.Command
}