I’m on #IA4, writing it in Go. I see there are same topics for different languages, none of the solutions work here. I tried different versions of code (copy/pasted from code examples), none seems to pass the test.
When I execute the same curl command as test and run it myself, I get the correct response (see uploaded image), also in Chrome web console I can see the response, but for some reason it does not pass the codecrafters test. Any ideas?
package main
import (
"fmt"
"net"
"os"
)
func main() {
l, err := net.Listen("tcp", "0.0.0.0:4221")
if err != nil {
fmt.Println("Failed to bind to port 4221")
os.Exit(1)
}
for {
conn, err := l.Accept()
if err != nil {
fmt.Println("Error accepting connection: ", err.Error())
os.Exit(1)
}
go handleConn(conn)
}
}
func handleConn(conn net.Conn) {
response := "HTTP/1.1 200 OK\r\n\r\n"
fmt.Println("Writing response", response, []byte(response))
_, err := conn.Write([]byte(response))
if err != nil {
fmt.Println("Failed to write response: ", err.Error())
os.Exit(1)
}
}