types cleanup
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 28s
Build and Publish / BuildAndDeploy (push) Successful in 2m22s

This commit is contained in:
matst80
2024-11-12 18:17:43 +01:00
parent 3f8cdec9af
commit 7e0f070637
11 changed files with 75 additions and 73 deletions

View File

@@ -37,21 +37,21 @@ func CartListen(address string) (*CartServer, error) {
type TCPCartServerMux struct {
mu sync.RWMutex
listeners map[uint32]func(CartId, []byte) error
functions map[uint32]func(CartId, []byte) (uint32, []byte, error)
listeners map[CartMessage]func(CartId, []byte) error
functions map[CartMessage]func(CartId, []byte) (CartMessage, []byte, error)
}
func NewCartTCPServerMux() *TCPCartServerMux {
m := &TCPCartServerMux{
mu: sync.RWMutex{},
listeners: make(map[uint32]func(CartId, []byte) error),
functions: make(map[uint32]func(CartId, []byte) (uint32, []byte, error)),
listeners: make(map[CartMessage]func(CartId, []byte) error),
functions: make(map[CartMessage]func(CartId, []byte) (CartMessage, []byte, error)),
}
return m
}
func (m *TCPCartServerMux) handleListener(messageType uint32, id CartId, data []byte) (bool, error) {
func (m *TCPCartServerMux) handleListener(messageType CartMessage, id CartId, data []byte) (bool, error) {
m.mu.RLock()
handler, ok := m.listeners[messageType]
m.mu.RUnlock()
@@ -64,7 +64,7 @@ func (m *TCPCartServerMux) handleListener(messageType uint32, id CartId, data []
return false, nil
}
func (m *TCPCartServerMux) handleFunction(connection net.Conn, messageType uint32, id CartId, data []byte) (bool, error) {
func (m *TCPCartServerMux) handleFunction(connection net.Conn, messageType CartMessage, id CartId, data []byte) (bool, error) {
m.mu.RLock()
fn, ok := m.functions[messageType]
m.mu.RUnlock()
@@ -126,7 +126,7 @@ func (m *TCPCartServerMux) HandleConnection(connection net.Conn) error {
}
}
func (m *TCPCartServerMux) HandleData(connection net.Conn, t uint32, id CartId, data []byte) {
func (m *TCPCartServerMux) HandleData(connection net.Conn, t CartMessage, id CartId, data []byte) {
status, err := m.handleListener(t, id, data)
if err != nil {
log.Printf("Error handling listener: %v\n", err)
@@ -142,13 +142,13 @@ func (m *TCPCartServerMux) HandleData(connection net.Conn, t uint32, id CartId,
}
}
func (m *TCPCartServerMux) ListenFor(messageType uint32, handler func(CartId, []byte) error) {
func (m *TCPCartServerMux) ListenFor(messageType CartMessage, handler func(CartId, []byte) error) {
m.mu.Lock()
m.listeners[messageType] = handler
m.mu.Unlock()
}
func (m *TCPCartServerMux) HandleCall(messageType uint32, handler func(CartId, []byte) (uint32, []byte, error)) {
func (m *TCPCartServerMux) HandleCall(messageType CartMessage, handler func(CartId, []byte) (CartMessage, []byte, error)) {
m.mu.Lock()
m.functions[messageType] = handler
m.mu.Unlock()