Go: static file server
Oct 10, 2016
1 minute read

I started learning Go about 3 months ago, back in July. One of the things that struck me early on was how easy, accessible, and fun it was, especially when it came to doing things on the web.

At work last week, there was a situation where an emergency firewall and router replacement would have interrupted communication to a static file server that we depedended on for CI. The solution was this:

package main

import "net/http"

func main() {
    http.ListenAndServe(":8080", http.FileServer(http.Dir("/app/mirror")))
}

plus a scrach Docker container:

FROM scratch
ADD main /

CMD ["/main"]

We spun up a new VM and deployed in less time than it took to SCP files over to the new mirror.

wow

Unfortunately, we ended up not using it becuase of some other reason, but at least we didn’t waste too much time.



comments powered by Disqus