I’ve been very quiet here for some time, basically because I’ve been too busy building things to write, although I have started covering non-technical startup engineering topics over on Medium (so check those out if you’re interested).
Time to start adding at least some short bits here, though. Recently I’ve been getting addicted to coding in Go, which reminds me of my old C programming days but with most of the ugly stuff sanded off. It’s simple, fast, clean and easy to read, “object oriented” in the ways that matter (interfaces), and the packaging and dependency management so far seems well-thought-out.
Alongside a growing belief that microservices (or whatever you want to call it since that term is so trendy now) are the way to go once a system reaches a certain size, and a desire to make things API-driven, I threw together an extremely simple web service skeleton in Go. It doesn’t do much — it’s there to serve as a quick starting point, including a Dockerfile and process for building the Docker image.
The web service uses Martini, which is a nice clean layer on top of the standard HTTP library. This example service really just shows its routing and ability to serve static assets. The repository is here: https://github.com/masonoise/go-service-example
You can clone the repository, run “godep save -r” since the import in the server.go file expects the Martini dependency to be vendored, and then “go run server.go” will bring it up locally. The README gives the simple steps to build and run a Docker image in a way that results in an extremely small image. All credit for this goes to Travis Reeder / Iron.io thanks to this very handy blog post.
All of the code here is in the server.go file, which is (I think) self-explanatory. Note that getting this running assumes you have Go installed, your GOPATH set up, and so forth. Getting the Docker image running of course assumes you have the Docker Toolbox installed and Docker running.
Try it out, and enjoy!