Go » History » Revision 3

Revision 2 (Misha Zatsman, 09/05/2014 03:33 PM) → Revision 3/11 (Misha Zatsman, 12/12/2014 09:31 PM)

h1. Go 



 h2. Using Go with Arvados 

 h3. Install Go 

 If you're installing Go on your linux machine you'll want to follow the "tarball instructions": to get the latest stable version, because if you use <code>apt-get</code> you'll get an outdated version. 

 The first time you install Go, you'll need to set @GOPATH@ to an empty directory.    The Go toolchain will install Go packages and dependencies here.  

 export GOPATH=~/gocode 
 mkdir -p $GOPATH 

 The rest of these instructions assume that you have a working Go installation on your system, and that your @GOPATH@ environment variable is set appropriately. 

 h3. Install Arvados source 

 Clone the Arvados git repository, if you have not already: 

 git clone git:// 

 *Note:* If you are an authorized committer, clone instead so you may push directly to 

 h3. Tell Go to use your local Arvados source 

 This step ensures that your development environment uses your locally-modified code, instead of fetching the master branch from 

 mkdir -p $GOPATH/src/ 
 ln -s ~/arvados $GOPATH/src/ 

 Reason: The Keepstore and Keepproxy packages import other Go packages from the Arvados source tree. These packages have names like: 


 When the Go compiler needs to import one of these packages, it will look in @$GOPATH/src@ for the package source code. If it does not find the code locally, it will fetch the code from automatically.    This symlink ensures that Go will find your local source code under @$GOPATH/src/ 

 h3. Run some tests 


 cd ~/arvados/services/keepstore 
 go test 

 The @go test@ command will print a few dozen lines of logging output.    If the tests succeeded, it will print PASS followed by a summary of the packages which passed testing, e.g.: 

 ok   	 _/home/you/arvados/services/keepstore 	 1.023s 

 h2. Go SDK 


 h2. Learning Go 

 Getting good at Go, and concurrency/goroutines in particular, is an excellent use of time. 

 h3. Introductions 
 * "Go Tour": is a great way to spend a few hours getting your feet wet. 
 * "Effective Go": The web site says that you should do both the tour and the language specification first before reading this, but honestly, I think it's ridiculous to try to read the language specification before you even start writing code in the language. I wouldn't try to read either the specification or "Effective Go" in depth before trying to write any code, but they're both at least worth skimming at this point. 
 * The slides for Rob Pike's talk on "Go Concurrency Patterns": I haven't watched all of the talks yet; these slides are really nice because they show very elegant ways of using channels and goroutines to build rich and complex concurrent abstractions. 
 * "The package documentation.": Note that the package docs include links to web versions of the package source code, which help very much in learning idiomatic Go patterns. 

 h3. Resources 

 h4. Free online resources: 


 h4. Books 

 * (Free!) 
 * "Programming in Go": (a bit dated now)