func main() {
fmt.Println("Hello, London Gophers!")
}
We follow the Go Code of Conduct and the Contributor Covenant, in summary:
- Treat everyone with respect and kindness.
- Be thoughtful in how you communicate.
- Don’t be destructive or inflammatory.
Visit the Go London Study Group Meetup for details of our IRL study group meetings.
Find us on Slack in the #london-study-group
channel of the gophers.slack.com
workspace.
Our study material is: The Go Programming Language by Alan Donovan and Brian W. Kernighan
Work through the material at a speed that suits you. We also have open space meetups to meet to chat about Go and the book etc. So just join in any time! :)
To begin, create your own directory in the workspaces directory,
work through the book exercises, and add your code there. When committing to the
repo just commit directly to master
but before you do so make sure you run
git pull -r
(-r
to rebase) before you push, to avoid merge commits. It may be
easier to instead run:
git config branch.autosetuprebase always
...in the repository directory to ensure that git pull always performs a rebase,
rather than a merge, on git pull
.
To do this for all repositories (a global setting) use:
git config --global branch.autosetuprebase always
You can add your code in separate directories if you're using Go Modules or if you're using a GOPATH you could structure your code as in the GOPATH Project Structure section.
If you need the exercises from the book, they're available in exercises.tar.gz zipped archive but these are already in the book so you might not need them.
It may be convenient to install the latest version of Go through the Homebrew and Linuxbrew package managers.
brew install go
The https://golang.org/dl/ page contains distros for Windows, MacOS, Linux, and source. The installation instructions explains how to install them.
You can grab the code samples used in the book (which you update for a bunch of the exercises) by running such as:
go get gopl.io/ch1/helloworld
(This will get the helloworld
code, plus the other examples).
There are two main options, by setting a GOPATH
and having all of your code in one
location or using Go Modules which allow you to split your code into separate
locations. It might be easier to use a GOPATH pointing to all of your workshop
code but you might find modules more appropriate.
The traditional way to run/build Go code (prior to Go Modules) is using a
GOPATH. You should set your $GOPATH
to your current directory, such as:
export GOPATH=/home/gopherg/eng-golang-workshop/workspaces/gogopher
To run some code you can then use:
go run gopl.io/ch1/helloworld
(which actually builds then executes /home/gopherg/eng-golang-workshop/workspaces/gogopher/src/gopl.io/ch1/helloworld/main.go
)
To build it and output in your $GOPATH\bin
directory:
go build -o $GOPATH/bin/helloworld gopl.io/ch1/helloworld
To get another module (such as the imaginary some/dependency
):
go get github.com/some/dependency
...and this will then be downloaded to $GOPATH/src/github.com/some/dependency
and
imported with import "github.com/some/dependency"
When using GOPATH your project structure may be something like:
workspaces
gogopher\
bin\
helloworld
...
src\
gogopher.io\
ch1\
ex1_1\
main.go
...
Go modules are an new feature in Go 1.11 which removes the need to
have a $GOPATH
set.
To use modules in your project directory, run:
go mod init example.com/foo
...where example.com
is replaced with your own domain name (or something like
github.com
if your code is in a github repo) and foo
is your package/component name.
This will create a file called go.mod
.
If you have a main function in your project directory you can also run your code using:
go run .
...and build it using:
go build .
...etc.
To include a module to your project you can add the external module to your
go.mod
file which would look like:
module example.com/foo
require (
github.com/some/dependency v1.2.3
)
...then import it and use it in your code:
package main
import "github.com/some/dependency"
func main() {
dependency.f()
}
Your own local packages are imported such as import "example.com/foo/package"
.
Delve is is a debugger for Go. To install run:
go get -u github.com/derekparker/delve/cmd/dlv
To see the available commands, run dlv
then help
at the (dlv)
prompt.
GoLand is a new commercial Go IDE by JetBrains aimed at providing an ergonomic environment for Go development.
The new IDE extends the IntelliJ platform with coding assistance and tool integrations specific for the Go language.
If you follow similar instructions to get go support for emacs (OS X) as below http://tleyden.github.io/blog/2014/05/22/configure-emacs-as-a-go-editor-from-scratch/
And you run into the following error when trying to get auto-complete to work.
Error running timer ‘ac-update-greedy’: (file-missing "Searching for program" "No such file or directory" "gocode")
Error running timer ‘ac-show-menu’: (file-missing "Searching for program" "No such file or directory" "gocode")
Error running timer ‘ac-update-greedy’: (file-missing "Searching for program" "No such file or directory" "gocode"
Then the problem is probably down to gocode
not being available in your path:
https://emacs.stackexchange.com/questions/10722/emacs-and-command-line-path-disagreements-on-osx
So if you edit /etc/paths.d/go
and add the path to the bin directory of your project it should fix problem.
Visual Studio Code is a lightweight but powerful source code editor with support for debugging, embedded Git control, syntax highlighting, intelligent code completion, snippets, and code refactoring. Visual Studio Code is based on Electron and uses the Blink layout engine. Vscode uses the same editor component as Atom (codenamed "Monaco").
The Go extension for Visual Studio Code, provides language features such as IntelliSense, code navigation, symbol search, bracket matching, snippets etc.
There are three kinds of IDEs:
- A character driven IDE such as unix, emacs or vi
- A closed environment with its own bespoke tooling such as eclipse, visual code, intellij, atom, GoLand
- An integrating environment that integrates tools from outside inwards such as plan9 and acme.
Atom supports Go development with the go-plus package.
To use Delve inside Atom, install the go-debug package.
To run your Go code in Atom, install the atom-runner package.
Source code: The Go Programming Language
YouTube: Concurrency is not Parallelism by Rob Pike
All exercises from The Go Programming Language are copyright 2016 Alan A. A. Donovan & Brian W. Kernighan and included with permission from the authors.
All submitted code is covered under Apache License 2.0.