by lelanthran · 1y ago · 0 comments
1. You just want to serve static files from your blog? Install a webserver and knock yourself out in your editor, creating html and css (and maybe js) files.
2. You want to serve static files, with some dynamic crap stuffed inside here and there like the examples given in the article? Install the mod_php or equivalent for your webserver, and go mad with the editor.
3. You want fully generated content? Install one of the many backend frameworks in any language you want to use, and then go mad in your IDE.
What use-case does "one binary I wrote in Go" satisfy that isn't covered above? From everything I gleaned from the article, the PHP solution is even easier, while still technically being "one single binary".
EDIT: as an example of over-engineering, here is the authors code for a specific use-case:
func ipHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
fmt.Fprintf(w, r.Header.Get("X-Forwarded-For")+"\n")
}
...
http.HandleFunc("/ip", ipHandler)
And here is the equivalent in PHP: header('Content-Type: text/plain');
echo $_SERVER['REMOTE_ADDR'];In .NET land, one of the top reasons to go all-in with a single exe web server would be performance. Kestrel can be unbelievably fast if you remove all of the layers of indirection like IPC and hosted SQL. I've got dynamic HTML pages that render in <100uS and that includes managing session state and other queries into SQLite.
Concerns like accidentally showing up on the front page of HN or even petty DDOS attempts can be often be ignored when you are able to serve content this quickly.
The other major reason I like it is having everything in one type system and debugger experience. I can set a breakpoint anywhere and inspect everything.
(Points to a myriad of Go functions that do in eight or nine lines what other languages do in two)
For instance, PyTorch is simple until you have a __need__ (e.g., rfft/irfft with bfloat16) to drop to CUDA and, in so doing, break autograd and all kinds of other things. Now you need to write a Torch extension and handle Meta/Fake tensors and the like if you want it to work with torch.compile. A lot of the simplicity goes right out the window.
If you run into this a lot, then you're doing something sufficiently weird for the simpler solution to, well, not be simpler.
I'm not a fan of Go myself, but I can see how a simple Go HTTP server fits the bill.