aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralex <[email protected]>2026-07-10 18:35:23 +0200
committeralex <[email protected]>2026-07-10 18:35:23 +0200
commit8be622b6b482b40f0b26259d6ed613a7d7307d53 (patch)
treec1c5933ce08a4d6abf56999ed284cd48894adfef
parentf6d82fac6f2f365e73254993782c490a6995fec3 (diff)
downloadredis-clone-8be622b6b482b40f0b26259d6ed613a7d7307d53.tar.xz
redis-clone-8be622b6b482b40f0b26259d6ed613a7d7307d53.zip
split the handlers into multiple maps with different paremeters/returns
-rw-r--r--main.go18
1 files changed, 13 insertions, 5 deletions
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