From 6745833aba4799104f299704af261696ce82b291 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 6 Jul 2026 13:55:11 +0200 Subject: refactored all handlers to take all args as a parameter --- main.go | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 81ff1fc..38ccd34 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,6 @@ import ( "fmt" "net" "os" - "strconv" "strings" ) @@ -55,31 +54,25 @@ func handleConnection(conn net.Conn) { switch { case command == "GET" && len(args) == 2: - handleGet(conn, args[1]) + handleGet(conn, args) case command == "SET" && len(args) == 3: - handleSet(conn, args[1], args[2]) + handleSet(conn, args) case command == "EXISTS" && len(args) == 2: - handleExists(conn, args[1]) + handleExists(conn, args) case command == "DEL" && len(args) == 2: - handleDel(conn, args[1]) + handleDel(conn, args) case command == "INCR" && len(args) == 2: - handleIncr(conn, args[1]) + handleIncr(conn, args) case command == "DECR" && len(args) == 2: - handleDecr(conn, args[1]) + handleDecr(conn, args) case command == "PING" && len(args) == 1: - handlePing(conn) + handlePing(conn, args) case command == "FLUSHALL" && len(args) == 1: - handleFlushall(conn) + handleFlushall(conn, args) case command == "RPUSH" && len(args) >= 3: handleRpush(conn, args) case command == "LRANGE" && len(args) == 4: - start, err1 := strconv.Atoi(args[2]) - stop, err2 := strconv.Atoi(args[3]) - if err1 != nil || err2 != nil { - conn.Write([]byte("-ERR value is not an integer or out of range\r\n")) - break - } - handleLrange(conn, args[1], start, stop) + handleLrange(conn, args) default: conn.Write([]byte("-ERR unknown command or wrong arguments\r\n")) } -- cgit v1.2.3