Custom Vagrant Cloud Versioned Box Host

With the recent addition of Atlas to the Hashicorp arsenal, Vagrant got an update to be integrated into Atlas for hosting your VM boxes and handling versioned updates. If you are still looking to have your boxes versioned and are hosting them yourself, or your company has them private, you can still achieve versioning your boxes with the latest Vagrant (1.7.2) and some manual work. In this post I will go through:

  1. Basics of building a Virtualbox Vagrant box, just enough to follow along.
  2. Building a box metadata file, used to resolve box versions and download URLs.
  3. Hooking everything up with your Vagrantfile.
Read on →

Golang Documenting Package Examples

Go has been gaining a lot of popularity recently. With a lot of the success stories centered on the performance gains switching from other languages. For me a lot of the smaller features, that shows an attention to detail, which makes it enjoyable to code in. These details are also what will help the Golang community grow as well. One of these details is the built in documentation into the language.

There is a built in go doc command with the language where you can view your package documentation locally by running an http server to serve your docs. GoDoc is the main hosting for open source packages that will build docs for your package by doing a go get and generating docs. Read on →

Golang Timed Function Wrapper

Wrote this quick and probably dirty wrapper for timing functions in Go. TimedReturn returns an interface{} in case a return value is needed from whatever you are wrapping.

Read on →

Golang Package Version Flag

So you’ve built your first service using Go and have it deployed out into your production environment. With cross compiling built into Go it’s easy and almost trivial to build a new binary of your code and deploy updates. But what happens when you need to know what version of your code is where or how can you easily verify your new binary was deployed.

There is a built in library in Go that handles flag parsing, the flag package. Using the flag package is straight forward and allows us to use flags to pass to our binary to print a version out.

First lets start with a main package that imports the flag package. Read on →

Golang Current File Path

I recently needed to get the current file absolute path from a go file. You first need to get the runtime package which is a part of Go

import "runtime"

Next you can use the Caller method and capture the filename. We need to give this function a 1 to tell it to skip up a caller. You can read more about the function here

_, filename, _, ok := runtime.Caller(1)

The filename will be the path up to the current directory of the file that calls this function. The ok is to check if the function call was able to find the information requested.

So in practice if you wanted to get a config file up a directory and in a config directory you could do the following

filepath := path.Join(path.Dir(filename), "../config/settings.toml")