Writing an HTTP Server in Go from Scratch: Part 2
Published on: 2025-05-25 20:42:51
Follow along while I improve the HTTPServer I wrote from scratch in Go.
Last year I wrote a blog post explaining how I built my HTTP Server in Golang by following a Coder Crafters, I got some good feedback on it and improved the HTTP Server quite a bit, let’s dive into the changes!
The git repository is still available if you want to look at the whole codebase.
The first unit test
Let’s start by adding a unit test, I was relying on the Codecrafters test suite but now I want to have some of my own unit tests.
This should mimic the first stage of the Codecrafters test suit:
func TestServerStart (t * testing.T) { // Start the server router := server. NewServer () go router. Start () // Give the server a moment to start time. Sleep ( 100 * time.Millisecond) // Not the most robust, good enough to start // Try to connect to the server conn, err := net. Dial ( "tcp" , "localhost:4221" ) if err != nil { t. Fatalf ( "Could not connect to server: %v " , err) } defer conn. Close () t. Log (
... Read full article.