/go-workshop

A workshop for learning Go written to help my colleagues get going with writing an API in the Go language.

Primary LanguageGo

Go Workshop

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.

Prerequisites

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.

Getting started

  1. Clone this repository
  2. Make sure gin is installed: go get github.com/codegangsta/gin
  3. Run make t to run the tests
  4. Run make r to start the application or use gin --appPort 8080 -i
  5. Visit the following pages:

Gin can not be found

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:

Material

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

Useful commands

Some useful commands include:

  • go test: Runs your tests in the current package (We use make 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 called P02012-Go-Workshop

  • go fmt: Formats your Go code
  • go get: Downloads and installs go packages (dependencies)

For more useful commands see this article

Disclaimer

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!