I’m stuck on Stage #wy1
My solution is this, which looks almost the solutions provided in Code Examples, but I get error:
package main
import (
"bufio"
"fmt"
"net"
"os"
"strings"
)
// Ensures gofmt doesn't remove the "net" and "os" imports in stage 1 (feel free to remove this!)
var _ = net.Listen
var _ = os.Exit
func main() {
l, err := net.Listen("tcp", ":6379")
if err != nil {
fmt.Println("Failed to bind to port 6379")
os.Exit(1)
}
for {
conn, err := l.Accept()
if err != nil {
fmt.Println(err)
continue
}
go handleConnection(conn)
}
}
func handleConnection(conn net.Conn) {
defer conn.Close()
scanner := bufio.NewScanner(conn)
for scanner.Scan() {
text := scanner.Text()
if strings.TrimSpace(text) == "PING" {
conn.Write([]byte("+PONG\r\n"))
}
}
}
Here are my logs:
remote: [your_program] Logs from your program will appear here!
remote: [tester::#WY1] [client-1] $ redis-cli PING
remote: [tester::#WY1] [client-1] Received "PONG"
remote: [tester::#WY1] [client-1] > PING
remote: [tester::#WY1] write tcp [::1]:36870->[::1]:6379: write: broken pipe
remote: [tester::#WY1] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)
remote: