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.
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.
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.
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.
To install third-party libraries, use
go get command.
go get receives importpath in command-line and install related libraries.