httptest | Testing
In the standard library, there is a package called net/http/httptest where you can easily create a mock HTTP server.
httptest.NewServer takes an http.HandlerFunc which we are sending in via an anonymous function.
http.HandlerFunc is a type that looks like this: type HandlerFunc func(ResponseWriter, *Request).
All it's really saying is it needs a function that takes a ResponseWriter and a Request, which is not too surprising for an HTTP server.
It turns out there's really no extra magic here, this is also how you would write a real HTTP server in Go. The only difference is we are wrapping it in an httptest.NewServer which makes it easier to use with testing, as it finds an open port to listen on and then you can close it when you're done with your test.