This repository contains the Go code workshop to help colleagues get started with writing Go code. In the workshop we touch upon a few basic Go constructs and the Gin framework that allows us to easily build an API with only a few lines of code.
For this workshop you're required to have Go installed. You also might want to have Make installed to utilize the makefile commands.
During the workshop the GoLand IDE will be used by the host, but it's perfectly OK to use Visual Studio Code or any other IDE that can read Go code.
- Clone this repository
- Make sure gin is installed:
go get github.com/codegangsta/gin
- Run
make t
to run the tests - Run
make r
to start the application or usegin --appPort 8080 -i
- Visit the following pages:
If your shell is unable to find gin
, it means your PATH
environment variable
does not include the directory where go installs binaries.
Go to your home directory (cd ~
) and look for the go
directory, inside it there
should be a bin
directory where the binaries are installed.
Learn how to add this directory to your PATH
here:
The workshop is divided up in these 3 sections.
Section | Reference material | Exercises | Expected time | Description |
---|---|---|---|---|
Basics | Link | Link | 2 hours | Going over the basics of the Go language such as syntax, differences with OOP languages and exception handling |
API | Link | Link | 2 hours | Finishing the API with a few more routes like a POST route |
Useful patterns | Link | Link | 1 hour, 30 minutes | Providing a list of useful patterns to improve code testing and quality |
Some useful commands include:
go test
: Runs your tests in the current package (We usemake t
for this)go run
: Runs the application locally (but we're using gin for this workshop)go build
: Builds the application to a single binary calledP02012-Go-Workshop
go fmt
: Formats your Go codego get
: Downloads and installs go packages (dependencies)
For more useful commands see this article
Although we're experienced with Go, we're not experts. If you discover new/better ways to go about certain topics please let us know!