types cleanup
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user