Go » History » Version 1
Misha Zatsman, 09/05/2014 03:05 PM
1 | 1 | Misha Zatsman | h1. Go |
---|---|---|---|
2 | |||
3 | {{toc}} |
||
4 | |||
5 | h2. Using Go with Arvados |
||
6 | |||
7 | _Copied from [[Hacking Keep]]_ |
||
8 | |||
9 | h3. Install Go |
||
10 | |||
11 | If you're installing Go on your linux machine you'll want to follow the "tarball instructions":http://golang.org/doc/install#tarball to get the latest stable version, because if you use <code>apt-get</code> you'll get an outdated version. |
||
12 | |||
13 | 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. |
||
14 | |||
15 | <pre> |
||
16 | export GOPATH=~/gocode |
||
17 | mkdir -p $GOPATH |
||
18 | </pre> |
||
19 | |||
20 | 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. |
||
21 | |||
22 | |||
23 | h3. Install Arvados source |
||
24 | |||
25 | Clone the Arvados git repository, if you have not already: |
||
26 | |||
27 | <pre> |
||
28 | cd |
||
29 | git clone git://git.curoverse.com/arvados.git |
||
30 | </pre> |
||
31 | |||
32 | *Note:* If you are an authorized committer, clone @git@git.curoverse.com:arvados.git@ instead so you may push directly to git.curoverse.com. |
||
33 | |||
34 | h3. Tell Go to use your local Arvados source |
||
35 | |||
36 | This step ensures that your development environment uses your locally-modified code, instead of fetching the master branch from git.curoverse.com: |
||
37 | |||
38 | <pre> |
||
39 | mkdir -p $GOPATH/src/git.curoverse.com |
||
40 | ln -s ~/arvados $GOPATH/src/git.curoverse.com/arvados.git |
||
41 | </pre> |
||
42 | |||
43 | Reason: The Keepstore and Keepproxy packages import other Go packages from the Arvados source tree. These packages have names like: |
||
44 | |||
45 | <pre> |
||
46 | git.curoverse.com/arvados.git/sdk/go/keepclient |
||
47 | git.curoverse.com/arvados.git/sdk/go/arvadosclient |
||
48 | </pre> |
||
49 | |||
50 | 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 git.curoverse.com automatically. This symlink ensures that Go will find your local source code under @$GOPATH/src/git.curoverse.com/arvados.git/...@ |
||
51 | |||
52 | h3. Run some tests |
||
53 | |||
54 | e.g. |
||
55 | |||
56 | <pre> |
||
57 | cd ~/arvados/services/keepstore |
||
58 | go test |
||
59 | </pre> |
||
60 | |||
61 | 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.: |
||
62 | |||
63 | <pre> |
||
64 | PASS |
||
65 | ok _/home/you/arvados/services/keepstore 1.023s |
||
66 | </pre> |
||
67 | |||
68 | |||
69 | |||
70 | h2. Learning Go |
||
71 | |||
72 | Getting good at Go, and concurrency/goroutines in particular, is an excellent use of time. |
||
73 | |||
74 | h3. Introductions |
||
75 | |||
76 | * "Go Tour":http://tour.golang.org/ is a great way to spend a few hours getting your feet wet. |
||
77 | * "Effective Go":http://golang.org/doc/effective_go.html 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. |
||
78 | * The slides for Rob Pike's talk on "Go Concurrency Patterns":http://talks.golang.org/2012/concurrency.slide#1. 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. |
||
79 | * "The package documentation.":http://golang.org/pkg/ Note that the package docs include links to web versions of the package source code, which help very much in learning idiomatic Go patterns. |
||
80 | |||
81 | h3. Resources |
||
82 | |||
83 | h4. Free online resources: |
||
84 | |||
85 | * http://golang.org |
||
86 | * http://golang.org/doc/code.html |
||
87 | * http://tour.golang.org/ |
||
88 | * https://gobyexample.com/ |
||
89 | * http://learnxinyminutes.com/docs/go/ |
||
90 | |||
91 | h4. Books |
||
92 | |||
93 | * http://www.golang-book.com/ (Free!) |
||
94 | * "Programming in Go":http://www.amazon.com/Programming-Go-Creating-Applications-Developers/dp/0321774639/ref=pd_bxgy_b_img_y (a bit dated now) |