Go is an open source programming language. Go source can be easily compiled into native binaries of several platforms, which brings the potential of application programming. I’m learning the new language on my spare time. Here is my notes for Go language. The contents may change during my learning process.
Install Go on Unix
The main toolchain of Go language can be placed in any place and you need to set GOROOT and PATH variable to use these tools. Besides, you need a separated place to hold third-party libraries and set GOPATH and PATH variable to access it. A possible way is installing the main toolchain to /usr/local and place third-parties libraries under the subdirectory of home directory.
- http://golang.org The official site. Start here.
- http://www.golangpatterns.info/ Go best practices and design patterns.
- http://www.golang-book.com/ Free online book: An Introduction to Programming in Go
- Programming in Go, Mark Summerfield, Addison-Wesley Professional, 2012
- The Go Programming Language Phrasebook, David Chisnall, Addison-Wesley Professional, 2012
- An Introduction to Programming in Go, Caleb Doxsey, CreateSpace Independent Publishing Platform, 2012. There are also free online edition of this book.
- The Way To Go, Ivo Balbaert, iUniverse, 2012
godoc command to get help message for Go.
Look up a package. Because the message is long, using
less is recommanded.
Look up a function
Query by keyword
Start a local server.
Create a Go Project
Before creating your own Go project, read “How to Write Go Code”. Go code must be kept inside a workspace. Here is my demo toy project.
The content of main.go is as follows:
The above code converts all command arguments to float numbers; calculates the sum; prints out the result.
The content of basic.go is as follows:
The above code calculates the sum of an array of float numbers and return it.
The trick to compile Go project outside main Go directory is setting GOPATH in the command line interface. I writed the step in Makefile.
Install third-party libraries
To install third-party libraries, use
go get command.
go get receives importpath in command-line and install related libraries.