A request for a file that is not there should return a clean 404, not an error. Today you handle the missing-file case, completing a working static file server.
Return 404 when a requested file does not exist, and 200 when it does.
Reading a file can fail — most often because it is not there — and the file
handler must turn that into a 404 rather than a panic or a blank 200. Any
read error becomes “Not Found”; a successful read becomes the 200 you built,
with its Content-Type set.
With that, the chapter closes on a genuinely useful program: a static file server. Point it at a directory of HTML and assets, open a browser, and it serves the site — correct status codes, correct content types, missing files handled. The last chapter makes it robust and able to handle many clients at once.
data, err := os.ReadFile(full)if err != nil { // no such file, or unreadablereturn Response{Status: 404, Body: []byte("Not Found")}}return Response{Status: 200, Body: data, Headers: ...}