My Wishlist: Versioned Packages in Go

Posted by Baron Schwartz on Jul 18, 2013 10:33:00 AM

Go is great. I love it, and it’s my favorite language. But I have a feature request: support for specifying the required version of a package when importing it.

Versioned_Packages

This is probably a nightmare with a lot more complexity than I imagine, but for the purposes of this blog post, let’s pretend that it’s simple:

import (
   "github.com/VividCortex/ewma" `v1.0`
)

Notice the tagged version number after the import statement. Imagine now that “go get” treats that as a tag in the version control system — as far as I know every VCS supported by “go get” supports tagging.

This would make life simpler for us at VividCortex, because we’re currently doing this with special Godeps files in the root of our repos:

github.com/VividCortex/ewma v1.0

And we use a Bash script to help us fetch those dependencies and check out the correct version:

while read dependency; do
  x=( $dependency )
  package=${x[0]}
  version=${x[1]}
  go get -u -v $package
  echo "Setting Go Package: $package to version $version"
  cd $GOPATH/src/$package && git checkout $version && echo "Done"
done < Godeps

It works. But it’d be nicer if it were part of the language. If wishes were horses!

(Pic credit)

Recent Posts

Posts by Topic

see all