Skip to content

Latest commit

 

History

258 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Learning Go: Basic Go exercises

A series of basic Go exercises inspired from the Go: Bootcamp Course. Solving all exercises will not make you a Go ninja, but it should be enough to get you started.

Getting started

Change to the root of the git repo and generate the exercises:

echo <MY-STUDENT-ID> > STUDENT_ID
git add STUDENT_ID
git commit -m 'student id added'
make generate

Your student id should always be available in the file named STUDENT_ID in the main directory. You can override this by setting the id in the STUDENT_ID environment variable.

STUDENT_ID=<MY-STUDENT-ID> make generate

Solve the exercises

Write code

Go through the subdirectories, preferably in the same order as the file names, understand the exercise specified in the README.md file, and insert your solution into exercise.go near the placeholder.

Once done with the exercise in the directory <exercise-directory>, make sure to git-add and git-commit your solution.

git add <exercise-directory>/exercise.go
git commit -m 'solved <exercise-directory>'

You can divide your code into as many files as you like but don't forget to add each file to your git repo.

Test

At any point in time you can test your solutions as follows.

make test

Keep track of repo updates

Sometimes we update the main git repo to fix bugs or add new exercises. The below workflow shows how to update your local working copy from the master without overwriting your solutions already written.

Warning Make sure to commit all your code into git: this will guarantee that you will never lose your solutions even if some of the below steps go wrong. You can also back up your git repo, but please make sure your solutions are kept private (a private GitHUb repo will do it).

With all local changes committed to git

If you have a clear git tree with all your changes committed, the below should update only the files that change in the master.

git pull --rebase

With local changes in the working directory

If you have uncommitted changes, follow the below steps.

  1. Store your changes temporarily.

    git stash
  2. Pull updates.

    git pull
  3. Restore your changes.

    git stash
  4. Optional: fix conflicts and re-run tests.

Add a new exercise

Add a new subdirectory and add the following files:

  • exercise.yaml: An exercise definition with a set of inputs, from which make generate will choose one by hashing on the student id to generate the exercise.
  • exercise.go: Placeholder for the solution.
  • .README.md: a README template with instructions.
  • .exercise_test.go: the test file to check your solutions.

If you add a new top-level directory, don't forget to include it in the EXERCISE_DIRS in the Makefile.

Each exercise directory is also listed in EXERCISES in the Makefile. That list is what make generate writes and what make clean removes, which keeps the two symmetric: a cleaned tree can always be regenerated. Add new exercises there too.

Then run make clean, this will add the placeholders for the exercise (these will be overwritten by make generate), add all files in the exercise dir to the git repo, and git-push.

Complete the labs

Labs tasks are located in the 99-labs folder. The labs give you hands-on development and deployment experience. You will learn how to build and containerize Go programs as well as how to run them in Kubernetes. Each lab contains a README that gives you context and specifies the lab exercises. The labs depend on each other, so it is recommended to complete them one after the other.

Each lab README walks you through the checks by hand, with kubectl and Minikube, which is how you are meant to work through them. Once you are done, make lab-test builds your container images, brings up a throwaway Kubernetes cluster, deploys your own manifests into it and runs every lab check against them, so you get a single pass or fail. It needs a container engine, and takes a few minutes to run.

make ci-test           # test exercises, then every lab
make lab-test          # test all the labs
LAB=05 make lab-test   # test only lab 05

Note

The CI tests are experimental: they pass in our tests, may not pass in yours. If the CI tests fail then that may not necessarily indicate a problem with your code. If you suspect the tests are wrong, please file a GitHub issue and copy-paste the test logs, we will investigate.

You can also run the checks against a cluster you already have, Minikube included. Build the images into that cluster, then point the tests at it with your usual KUBECONFIG:

cd 99-labs/ci
LABS_EXTERNAL_CLUSTER=1 LABS_SOURCE=$(git rev-parse --show-toplevel) go test ./ -run TestLab04 -v

See 99-labs/ci/README.md for the details.

Note

This repo is set up to automatically run the test suite at GitHub and report the result in a small status check: a green check mark if all tests (homework+labs) pass, a little red cross if not. This requires your student if in STUDENT_ID: make sure to commit and push it. Don't forget to commit all your lab solutions and manifests as well!

Clean up

Reset all generated files to the default placeholder. Warning: this will drop all your uncommitted local changes, use it at your own risk.

make clean

Also reset the student id: this is required before pushing any modification to any of the exercises.

make realclean

Help

Ask any questions or file an issue at the original GitHub repo.

License

Copyright 2021-2023 by its authors. Some rights reserved. See AUTHORS.

Creative Commons Attribution-NonCommercial-ShareAlike - see LICENSE for full text.

Acknowledgments

Examples adopted from the Go: Bootcamp Course.

About

Exercises for learning Go and cloud native design

Resources

Stars

12 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages