From 8be622b6b482b40f0b26259d6ed613a7d7307d53 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 10 Jul 2026 18:35:23 +0200 Subject: split the handlers into multiple maps with different paremeters/returns --- main.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 570b512..a7f6d47 100644 --- a/main.go +++ b/main.go @@ -118,11 +118,19 @@ func handleConnection(conn net.Conn) { command := strings.ToUpper(args[0]) - if handler, ok := baseCommandRegistry[command]; ok { - conn.Write(serializeRESP(handler(args))) - } else { - conn.Write(serializeRESP(errors.New("unknown command"))) - } + switch { + case baseCommandRegistry[command] != nil: + handler := baseCommandRegistry[command] + conn.Write(serializeRESP(handler(args))) + + case connectionCommandRegistry[command] != nil: + handler := connectionCommandRegistry[command] + handler(conn, args) + + default: + errMsg := fmt.Sprintf("ERR unknown command '%s'", command) + conn.Write(serializeRESP(errors.New(errMsg))) + } } } \ No newline at end of file -- cgit v1.2.3