1. 10
  1.  

  2. 4

    This is a story about how Go is awesome at creating these super small HTTP servers. Most of the time you can get away with just using the stdlib. Instead of spending hours learning how to config Nginx or some other webserver, it can be as efficient to write your own specialized server.

    For example, two months ago, one customer was serving their frontend using nodejs, and it was taking quite a bit of memory in the cluster. The docker image was also quite large with all the runtime. Two hours later, I had thrown together a statically built Go program that is specialized to serve SPA1. They have been using it happily ever since. And if they need some extra feature, I know that it will be as easy, or even easier for me to add exactly what they need.

    1. 8

      For what it’s worth I could have probably gotten away with something like this for Nginx config (I haven’t tested this but I’m at least 98% certain it would only need minor adjustments to work properly):

      server {
      	listen [fda2:d982:1da2:180d:b7a4:9c5c:989b:ba02]:43705;
      	location ~ ^/(?<service>[a-zA-Z]+)$ {
      		proxy_pass http://unix:/srv/within/run/$service.sock:/metrics;
      	}
      }
      

      However doing it with the Go standard library does get to show off how easy Go makes it to do amazingly hacky things without using anything but the standard library. Go is nice for these things. I wish that level of simplicity in usage was true about other aspects of the tooling like Go modules, but that’s a rant for another day.

      1. 3

        I wish that level of simplicity in usage was true about other aspects of the tooling like Go modules, but that’s a rant for another day.

        My thoughts as well. Reading your Go really reminded me of its (perhaps former?) “cultural agenda of radical simplicity”. Also, thanks to Mara for the NixOS service. Also love to see Nix get involved with anything :-).