Organizing Code to Support Go Get
For those of you who are like me, trying to learn the Mac and Linux operating systems, Golang programming and deployment constructs all at the same time, I feel your pain. I have been building a Go application for a couple of months on my Mac and it was time to deploy the code on a local Ubuntu server. I was having a really tough time and it was turning into a disaster. Like always, I kept telling myself, I must be doing something wrong.
Well, I was, big-time. Let me put it this way. After spending 2 days reorganizing repositories and code, I finally figured out how the Go tool works. Now I can update my development environment, deploy, build, install and update my Go applications on any machine with one simple call to go get.
I am sure there are several ways you can organize code that will work with the Go tool. What I am going to present is working for me and I wish I knew all of this when I started. There are a 1000 ways to skin a cat and we all have our favorite way, this one is now mine.
Everything we do in Go should be based on what the Go tool can do. Going off the reservation will get you in trouble, I am living proof. One special command we are going to focus on is get. The get command will download code, build and install packages and produce an executable binary if you are building a program. It is very smart and can read your code to find dependences that it will download, built and install as well. That is, if everything is structured and set correctly.
This document explains all the things the Go tool can do:
http://golang.org/cmd/go/ (http://golang.org/cmd/go/)
But I want to concentrate on this section:
http://golang.org/cmd/go/#hdr-Remote_import_path_syntax (http://golang.org/cmd/go/#hdr-Remote_import_path_syntax)
Even as I read this document now I have a hard time understanding what it is trying to tell me.
I use Github but you don’t have to. The Go tool supports Github, Mercurial, Subversion and Bazaar out of the box. If you are not using any of these systems for version control, there are ways to give the Go tool the information it needs to support your version control system.
When I say the Go tool supports these version control systems it’s a bit vague right now, so let’s jump into this. Everything starts with a repository, so let’s look at the ones I have for my project. I have two accounts in Github. One is called goinggo which contains all my shared and reusable repositories. The other is ArdanStudios which contains my private repositories.
Here is the goinggo repository: