Compare commits

...

3 Commits

Author SHA1 Message Date
06e5e7cd9c Change name of module 2024-11-27 13:32:31 +02:00
b26b0512f2 Move all types in tcpclient to types.go 2024-10-23 12:40:36 +03:00
ecb6e12425 Move all types in tcpserver to types.go 2024-10-23 12:40:36 +03:00
7 changed files with 79 additions and 65 deletions

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"time" "time"
"git.qowevisa.me/Qowevisa/tcpmachine/tcpclient" "git.qowevisa.me/qowevisa/tcpmachine/tcpclient"
) )
func main() { func main() {

View File

@ -5,7 +5,7 @@ import (
"net" "net"
"time" "time"
"git.qowevisa.me/Qowevisa/tcpmachine/tcpserver" "git.qowevisa.me/qowevisa/tcpmachine/tcpserver"
) )
func main() { func main() {

2
go.mod
View File

@ -1,3 +1,3 @@
module git.qowevisa.me/Qowevisa/tcpmachine module git.qowevisa.me/qowevisa/tcpmachine
go 1.20 go 1.20

View File

@ -8,20 +8,9 @@ import (
"net" "net"
"strings" "strings"
"git.qowevisa.me/Qowevisa/tcpmachine/tcpcommand" "git.qowevisa.me/qowevisa/tcpmachine/tcpcommand"
) )
type ClientConfiguration struct {
MessageEndRune rune
MessageSplitRune rune
//
Status uint32
ErrorResolver func(chan error)
//
ServerHandlerFunc func(server net.Conn)
//
}
func GetDefaultConfig() *ClientConfiguration { func GetDefaultConfig() *ClientConfiguration {
return &ClientConfiguration{ return &ClientConfiguration{
MessageEndRune: '\n', MessageEndRune: '\n',
@ -34,26 +23,6 @@ func GetDefaultConfig() *ClientConfiguration {
} }
} }
type ErrorResolverFunc func(errors chan error)
type Client struct {
MessageEndRune rune
MessageSplitRune rune
//
addr string
Status uint32
exit chan bool
Server net.Conn
IsConnected bool
//
ServerHandlerFunc func(server net.Conn)
//
ErrorsChannel chan error
ErrorResolver ErrorResolverFunc
//
Commands []tcpcommand.Command
}
func CreateClient(addr string, options ...ClientOption) *Client { func CreateClient(addr string, options ...ClientOption) *Client {
conf := GetDefaultConfig() conf := GetDefaultConfig()

38
tcpclient/types.go Normal file
View File

@ -0,0 +1,38 @@
package tcpclient
import (
"net"
"git.qowevisa.me/qowevisa/tcpmachine/tcpcommand"
)
type ClientConfiguration struct {
MessageEndRune rune
MessageSplitRune rune
//
Status uint32
ErrorResolver func(chan error)
//
ServerHandlerFunc func(server net.Conn)
//
}
type ErrorResolverFunc func(errors chan error)
type Client struct {
MessageEndRune rune
MessageSplitRune rune
//
addr string
Status uint32
exit chan bool
Server net.Conn
IsConnected bool
//
ServerHandlerFunc func(server net.Conn)
//
ErrorsChannel chan error
ErrorResolver ErrorResolverFunc
//
Commands []tcpcommand.Command
}

View File

@ -9,11 +9,9 @@ import (
"net" "net"
"strings" "strings"
"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
}