Setting Up Golang Like a Rubyist

Getting into the Go Programming Language

I use Ruby in my day job, but recently I’ve been dabbling with Go. The install docs give you an easy way to setup if you’re on Linux:

1
2
export PATH=$PATH:/usr/local/go/bin
3

But I’m used to RVM and other environment managers – where is the RVM for Go?

Using the Ruby ecosystem can kind of spoil you a bit as a developer as I’ve found while exploring Go. The tooling is easy to use and setup. I’ve gotten used to the workflow of creating gemsets specifically for particular applications (or using bundler if you prefer) and being able to switch from one to the other using a command line tool like rvm. I rarely have to think about exporting PATH variables.

Fortunately, there is GVM

Step 1 – Install GVM

There are some pretty clear instructions the GVM README which will let you install GVM.

Step 2 – Create a pkgset (similar to a gemset in rvm)

1
2
$ gvm pkgset awesomecode
3

Step 3 – Edit GOPATH and PATH environment variables

In your terminal type:

1
2
$ gvm pkgenv awesomecode
3

This will open something like the below configuration file in your favorite editor specified by the environment variable: $EDITOR. You can also navigate directly to it where you installed your .gvm folder. In my case, it was at $HOME/.gvm/environments and was called go1.4@awesomecode.

01
02
##MY ORIGINAL GOPATH
03
# export GOPATH; GOPATH="/home/bruce/.gvm/pkgsets/go1.4/awesomecode:$GOPATH"
04
 
05
##EDITED GO
06
export GOPATH; GOPATH="/home/bruce/.gvm/pkgsets/go1.4/awesomecode:$HOME/Documents/github_code/awesomecode/go:$GOPATH"
07
 
08
##MY ORIGINAL PATH
09
# export PATH; PATH="/home/bruce/.gvm/pkgsets/go1.4/awesomecode/bin:${GVM_OVERLAY_PREFIX}/bin:${PATH}"
10
 
11
##EDITED PATH 
12
export PATH; PATH="/home/bruce/.gvm/pkgsets/go1.4/awesomecode/bin:${GVM_OVERLAY_PREFIX}/bin:$HOME/Documents/github_code/awesomecode/go/bin:${PATH}"
13

Step 4 – Other Notes

The other thing I’m learning is that running go requires a very specific directory structure. In the /awesomecode/go directory, I had to create pkg, src, and bin directories in addition to the main directory that housed my hello_world.go file.

Sources:

I stole shamelessly from this post by vastbinderj. I’m writing this to document this so I don’t forget. Thanks open source!

My Year of Software – A Review of 2014

Ten software lessons in 2014

Lesson 1 – Building a Rails API

In 2014, I built a backedn Rails 4.2 API using the rocket_pants gem and used another Rails application to view the API data. I learned to watch how many objects I was creating and how important it was to use performance monitoring tools like New Relic to ensure I was hitting ~200 millisecond response times to ensure a great user experience.

Lesson 2 – Vimgolf is great for teaching yourself vim one day at a time

I’ve been playing Vimgolf and learning a few vim tricks such as using gg to jump to the top of the file and Shift+G to jump to the bottom of the file.

Lesson 3 – Blogging is good for self-documenting

Blogging has been quite useful for documenting all the little tricks I’ve been using in my Rails applications, from testing elasticsearch with RSpec to saving nested attribute checkboxes with the cocoon gem.

Lesson 4 – You really learn by shipping applications that get used in production

Once you start getting customers telling you what’s broken and what can be improved, you get a bird’s eye view of not only how well you and the customer both understood the requirements and their translation into working software.

If you’ve been writing unmaintainable code, you’ll also experience the pain of trying to add new features quickly.

Lesson 5 – Portfolio applications (non-production) are great for testing new concepts

Portfolio applications are great for testing new ideas, but if they’re not being stress tested by actual users, you don’t get to the joy of writing performant code.

Lesson 6 – Sometimes big companies won’t take the risk of trying “new” technology

It could be because of tight deadlines or other developers aren’t comfortable with the latest stuff coming out. In that case, if you want to do it, hopefully you can find a good business case for it.

Lesson 7 – The only way to learn is to try

I really jumped into my first Rails application without knowing things like metaprogramming, SQL, and Vim. When I look back at how little I knew, I am sometimes amazed that anything got shipped! :)

Lesson 8 – The more I keep learning the more I realize how ignorant I am

When I look at what I consider are great programmers (Yehuda Katz, David Heinemeier Hansson, John Resig, and the list goes on…), I realize how little I know.

Lesson 9 – Logging is your best friend to ensure important data is not lost

Due to a tight shipping schedule, some controller parameter values were not being saved but I never realized it until the end user noticed it. Fortunately, we had been logging things with Papertrail, and so I was able to backfill the data.

Lesson 10 – Test Driven Development is your friend

Maybe experienced programmers like DHH (David H. Hansson) can get away without testing, but as I experienced in Lesson 9, a little testing would have ensured I didn’t have to manually backfill logged data into my Rails application database.

Camel Casing Your API Response in rocket_pants

What is rocket_pants?Rocket pants is a gem that gives you a set of tools for building an API in Ruby with Rails.Motivation for camel casingThe developer team decided we wanted to return camel-cased json responses, e.g.,{

Continue Reading …

Testing Elasticsearch In Your Rails 4 Application

What is Elasticsearch? Elasticsearch is an open-source real-time search and analytics engine that runs on top of Lucene, a Java-based indexing and search library.If you haven’t setup elasticsearch with your Rails application, you can read about

Continue Reading …

How to Implement jQuery Colorbox

How to Implement jQuery ColorboxWhat is jQuery Colorbox?jQuery Colorbox is a lightbox plugin that supports “photos, grouping, slideshow, ajax, inline, and iframed content.” In a nutshell, you can create nice looking popup boxes

Continue Reading …

How to Add jQuery UI Datepicker To Your Rails 4 Application With Formtastic and Cocoon

What is Formtastic, Cocoon, and jQuery UI Datepicker?Formtastic is a gem that lets you add forms more easily to your Rails application. Cocoon allows you to add dynamic nested forms to your Rails application using jQuery. jQuery-ui Datepicker

Continue Reading …

How To Move an Existing Github Repository to Bitbucket

Moving an Existing Github Repository to BitbucketHere is the link to the procedure on coderwall…

Continue Reading …

How To Save Nested Attribute Checkboxes With Formtastic and Cocoon and Avoid the TypeError

Avoiding the TypeError: can’t cast Array to stringRecently, I was inserting nested attribute checkboxes using Formtastic and Cocoon and was cruising along with all my other nested forms partials until I got a dreaded TypeError: can’t cast Array

Continue Reading …

How To Setup jQuery Autcomplete With Elasticsearch In Your Rails Application

What is jQuery autocomplete? The jQuery autocomplete plugin enables your users to receive suggestions while they type keywords in an input field. How do you use it with elasticsearch? If you haven’t setup elasticsearch with your Rails application,

Continue Reading …

How to Setup Elasticsearch in your Rails App in Production

Step 1 - Install elasticsearch in your Rails Application in ProductionIf you haven’t setup elasticsearch in your Rails application in development, this article tells you how to do so in LinuxStep 2 - Create the search indices on your Heroku

Continue Reading …