Go Static File Server

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!

Published 11 Oct 2016

Simon So
Principal @ Slalom Build