diff options
| author | alex <[email protected]> | 2026-07-10 18:35:23 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-10 18:35:23 +0200 |
| commit | 8be622b6b482b40f0b26259d6ed613a7d7307d53 (patch) | |
| tree | c1c5933ce08a4d6abf56999ed284cd48894adfef /main.go | |
| parent | f6d82fac6f2f365e73254993782c490a6995fec3 (diff) | |
| download | redis-clone-8be622b6b482b40f0b26259d6ed613a7d7307d53.tar.xz redis-clone-8be622b6b482b40f0b26259d6ed613a7d7307d53.zip | |
split the handlers into multiple maps with different paremeters/returns
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -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 |
