GithubHelp home page GithubHelp logo

go-course's Introduction

Go Training

Build Status Coverage GolangCI

Go Course lab assignments repository.

Prerequisites

Build, execute, test, lint

Run the hello-world sample with

go run 00_hello_world/juliaogris/main.go

Alternative build and execute a binary with

go build -o hello_world ./00_hello_world/juliaogris
./hello_world

Test it with

go test ./...

Lint it with

golangci-lint run

Review coverage with

go test -coverprofile=coverage.out ./... && go tool cover -html=coverage.out

Pre-PR checklist

  • Ensure your source code changes
    • Build
    • Test
    • Lint
    • Have 100% test coverage
  • Ensure good commit messages
    • Separate subject from body with a blank line
    • Limit the subject line to 60 characters
    • Use the imperative mood in the subject line
    • Do not end the subject line with a period
    • Wrap the body at 80 characters
    • Use the body to explain what and why vs. how
    • Use git rebase -i COMMIT_HASH to rework your commits if necessary
  • Fill in PR description and reference an Issue for instance with #6
  • Review the "Files changed" section of your PR
  • "Think of the reviewer: your code needs to be reviewable and that should be a prime concern when writing your code, commits and PRs." (@camh-anz)
  • Review a colleague's PR and add a link to the review in your own PR description

go-course's People

Contributors

ailyntang avatar alanhillgemann avatar alextmz avatar alfredxiao avatar anzboi avatar brnbke avatar brvishnu92 avatar cameronschafer avatar davidbroughsmyth avatar harirakr avatar hsy3418 avatar jessodri avatar jimbosoft avatar jimenezdav avatar joel00wood avatar juliaogris avatar lexual avatar lexual-anz avatar mohitnag avatar n0npax avatar nicholascross avatar nicko-lee avatar odrij avatar patrickmarabeas avatar pfannerj avatar runnerdave avatar samuong avatar sirigithub avatar willshen24 avatar willshen8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-course's Issues

Lab 2 - Bubble sort

Lab 2 - Bubble sort

  • Create an executable go program in directory 02_bubble/CameronSchafer
  • Write a function that returns a sorted copy of int slice s using Bubble sort:
func bubble(s []int) []int
  • Call fmt.Println(bubble([]int{3, 2, 1, 5})) in main to print: [1 2 3 5]
  • Bonus points: implement Insertion sort
func Insertion(s []int) []int
  • Extra bonus points: implement an O(n log(n)) sorting algorithm
func merge(s []int) []int

Lab 1 - fibonacci series

Create an executable go program in directory 01_fib/brvishnu92.
Write a function that prints the first n Fibonacci numbers.
Write test cases covering all function runs.

Sorted letter counts

  • Add Simple app to demonstrate sorted counts
  • Implement letters function to count runes in a string
  • Implement sortLetters function to sort rune counts
  • 100% coverage

Lab 1 Fib Sequence

This issue optimizes the iteration logic for generating fib sequences and uses tables for unit tests

Lab 3 - Letter frequency

Create an executable go program that takes a string as the input and returns a mapping of each letter to its frequency.

Lab 4 - numeronym

  • Create an executable go program in directory 04_numeronym/USERNAME
  • Write a function that returns a slice of numeronyms for its input strings:
func numeronyms(vals ...string) []string
  • Call fmt.Println(numeronyms("accessibility", "Kubernetes", "abc")) in main to print:
[a11y K8s abc]

IPAddr type and string formatting

  • Implement IPAddr type backed by an array of 4 bytes
  • Implement IPAddr related function to print IP address
  • Add simple application to demonstrate formatting
  • Add unit tests to cover string formatting of IPAddr

Lab02 implement bubble sort

  • Create an executable go program in directory 02_bubble/jonathanheaden
  • Write a function that returns a sorted copy of int slice s using bubble sort:

Numeronyms

  • Implement function that returns a slice of numeronyms for its input strings
  • Create a simple application to demonstrate
  • 100% test coverage

Lab 3 - Letter frequency

Lab 3 - Letter frequency

  • Create an executable go program in directory 03_letters/CameronSchafer
  • Write a function that returns a mapping of each letter to its frequency:
func letters(s string) map[rune]int

Write a function that returns a sorted slice of strings with elements "{key}:{val}". Use package sort:

func sortLetters(m map[rune]int) []string

Call fmt.Println(strings.Join(sortLetters(letters("aba")), "\n")) in main to print:

a:2
b:1

Bonus points: comprehensive tests

Lab 2 - Bubble and Insertion Sort

Create an executable go program in directory 02_bubble/brvishnu92.
Write function that returns a sorted copy of int slice s using bubble sort.
Write test cases covering all function runs.

Lab 7 - Errors

  • Create an executable go program in directory 07_errors/USERNAME

  • Copy the CRUD puppy from upstream master 06_puppy/USERNAME

  • Add a custom error type Error with fields Message and Code

  • Extend the Storer interface for all methods to also return error

  • Create errors for:

- Value < 0
- ID not found in Read, Update and Delete
  • Add locking for proper use of sync.Map

  • Bonus points: Add a third Storer implementation using LevelDB

Lab 2 - Bubble sort

Lab 2 - Bubble sort

  • Create an executable go program in directory 02_bubble
  • Write a function that returns a sorted copy of int slice s using Bubble sort:
func bubble(s []int) []int
  • Call fmt.Println(bubble([]int{3, 2, 1, 5})) in main to print: [1 2 3 5]
  • Bonus points: implement Insertion sort
  • Extra bonus points: implement an O(n log(n)) sorting algorithm

Lab 1 - fibonacci series

  • Create an executable go program in directory 01_fib
  • Write a function that prints the first n Fibonacci numbers
func fib(n int)
  • Call fib(7) in main to print
1
1
2
3
5
8
13
  • Bonus points: For negative n print Negafibonacci numbers.

Lab 1 - Fib Number

This issue solves the fib number sequence, by calling fib(n) it will print the first n fib numbers line by line,

Lab 1 Fibonacci sequence

Lab 1 - Fibonacci sequence

  • Create an executable go program in directory 01_fib
  • Write a function that prints the first n Fibonacci numbers
func fib(n int)
  • Call fib(7) in main to print
1
1
2
3
5
8
13
  • Bonus points: For negative n print Negafibonacci numbers.

Remove testify from hello world test

We want to encourage a basic understanding of testing in go works, which has been identified as a problem and is made worse by the reliance on rich third party libraries.

We want to start with the native testing package that all tests must use, before introducing testify that hides testing behind a richer framework.

Lab 6 - CRUD puppy with interface

  • Create an executable go program in directory 06_puppy/USERNAME

  • Implement a Puppy struct containing ID, Breed, Colour, Value

  • Create Storer interface with CRUD methods for Puppy

  • Write a MapStore implementation of Storer backed by a map

  • Write a SyncStore implementation of Storer backed by a sync.Map

  • Find hints at anz-bank/go-samplerest

  • Write tests against the Storer interface in a suite and run the suite with both implementations

crud_puppy

J. D. Frazer "Illiad", User Friendly - Crud Puppy

Clean up and unify CI configs

This repo has both Travis and Google Cloud Builds CI configurations, but there are some differences:

  1. Travis uses -race when it runs the tests, cloudbuilds does not.
  2. Cloudbuilds uses a different shell snippet to check for 100% coverage than travis uses. They should use the same.

-race was not used on cloudbuilds because it would fail:

Step #1 - "test": Running: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
Step #1 - "test": # runtime/race
Step #1 - "test": race_linux_amd64.syso: In function `__sanitizer::GetArgv()':
Step #1 - "test": gotsan.cc:(.text+0x4183): undefined reference to `__libc_stack_end'
Step #1 - "test": race_linux_amd64.syso: In function `__sanitizer::ReExec()':
Step #1 - "test": gotsan.cc:(.text+0x9797): undefined reference to `__libc_stack_end'
Step #1 - "test": race_linux_amd64.syso: In function `__sanitizer::InternalAlloc(unsigned long, __sanitizer::SizeClassAllocatorLocalCache<__sanitizer::SizeClassAllocator32<__sanitizer::AP32> >*, unsigned long)':
Step #1 - "test": gotsan.cc:(.text+0xaac1): undefined reference to `__libc_malloc'
Step #1 - "test": race_linux_amd64.syso: In function `__sanitizer::InternalRealloc(void*, unsigned long, __sanitizer::SizeClassAllocatorLocalCache<__sanitizer::SizeClassAllocator32<__sanitizer::AP32> >*)':
Step #1 - "test": gotsan.cc:(.text+0xca20): undefined reference to `__libc_realloc'
Step #1 - "test": race_linux_amd64.syso: In function `__sanitizer::InternalFree(void*, __sanitizer::SizeClassAllocatorLocalCache<__sanitizer::SizeClassAllocator32<__sanitizer::AP32> >*)':
Step #1 - "test": gotsan.cc:(.text+0x66e8): undefined reference to `__libc_free'
Step #1 - "test": collect2: error: ld returned 1 exit status

That is because the cloud-builder is an alpine image on which the race detector does not work because alpine is not glibc-based.

To make that work, we'll need to switch to a debian-based go cloud-builder.

Bubble and Insertion sort

  • Create simple application to demonstrate sorting
  • Create bubble sort function
  • Create insertion sort function
  • 100% coverage

Typo in 03_letters README.MD

The description in README file:
fmt.Println(strings.Join(sortLetters(letters("aba"))), "\n")

is supposed to be
fmt.Println(strings.Join(sortLetters(letters("aba")), "\n"))

Lab 3 - Letter frequency

  • Create an executable go program in directory 03_letters
  • Write a function that returns a mapping of each letter to its frequency:
func letters(s string) map[rune]int
  • Write a function that returns a sorted slice of strings with elements "{key}:{val}". Use package sort:
func sortLetters(m map[rune]int) []string

Call print(letters("aba")) in main to print:

a:2
b:1
  • Bonus points: comprehensive tests

Lab 8 - Project Layout

  • Copy the CRUD puppy from upstream master 07_errors/USERNAME
  • Create directory 08_project/USERNAME containing
├── README.md
├── go.mod
├── go.sum
├── pkg
│   └── USERNAME-puppy
│       ├── types.go
│       ├── types_test.go
│       ├── errors.go
│       ├── errors_test.go
│       └── store
│           ├── storer.go
│           └── .... store files and tests, e.g. mapstore.go
├── cmd
│   └── USERNAME-puppy-server
│       └── main.go
└── vendor
  • Add project introduction and how to build, run & test it to README.md

Lab 4 - Numeronym

Create an executable go program that returns a slice of numeronyms for input strings.

re: lab 1 fib sequence -- better to decouple fibonacci sequence calculation from IO

It's usually preferable to decouple logic from other concerns like input & output, formatting. I.e. if a function has logic to compute something, it probably shouldn't also do IO.

Why? Decoupling things into components or layers that each have fewer responsibilities usually produces code that is simpler and more re-usable.

In this case: better that the function that computes fibonacci sequence is NOT responsible for doing IO (formatting the numbers to an output stream).

For example, code to compute fibonacci sequence that also writes strings to some global variable is less likely to be usable or re-usable when compared to code that simply returns the computed sequence as a new value in some "natural" representation such as a slice of integers. If you want, you can then call some other function to format the sequence to a string, but perhaps some times you don't want to format anything to a string!

Other things that you might want to do with a fibonacci sequence:

  • sum the numbers in the sequence
  • find the max of the numbers in the sequence
  • transform the sequence in some way -- e.g. add 7 to all of the values, or produce the sequence of cumulative sums of the sequence (1 1 2 3 5 8 13 ... --> 0 1 2 4 7 12 20 33 ...)

It's much easier to do this if the sequence is represented as an array or slice of numbers, instead of as a formatted string!

Lab 9 - JSON puppy

  • Create directory 09_json/USERNAME containing a copy of upstream master

  • 08_project/USERNAME

  • Add JSON tags to puppy data type

  • Test marshalling and unmarshalling using require.JSONEq

  • Add command line flag -d FILE with long form --data FILE using kingpin.v2. FILE should contain an array of puppies in JSON format. Parse this file and store its contents.

Lab 1 - fibonacci series

  • Create an executable go program in directory 01_fib/CameronSchafer
  • Write a function that prints the first n Fibonacci numbers
func fib(n int)
  • Call fib(7) in main to print
1
1
2
3
5
8
13
  • Bonus points: For negative n print Negafibonacci numbers.

Upgrade CI version of go to 1.12.x

We recommend using go 1.12 in our docs for the course, but the CI tools (travis and golangci-lint) are both using go 1.11. Update the configs to use newer versions.

Travis can be configured to use go 1.12.x and golangci-lint can be updated to version v1.16.0 which contains go 1.12.

Lab 5 - Stringer

  • Create an executable go program in directory 05_stringer/USERNAME

  • Make the IPAddr type implement fmt.Stringer to print the address as a dotted quad

  • Find hints at Tour of Go Exercise: Stringers

  • Call fmt.Println(IPAddr{127, 0, 0, 1}) in main to print:

127.0.0.1

Lab3

  • Create an executable go program in directory 03_letters
  • Write a function that returns a mapping of each letter to its frequency:
func letters(s string) map[rune]int
  • Write a function that returns a sorted slice of strings with elements "{key}:{val}". Use package sort:
func sortLetters(m map[rune]int) []string

Call print(letters("aba")) in main to print:

a:2
b:1
  • Bonus points: comprehensive tests

Lab01 Fibonacci

Lab 1 - Fibonacci sequence

  • Create an executable go program in directory 01_fib
  • Write a function that prints the first n Fibonacci numbers

Lab 2 - Bubble sort

Create an executable go program that returns a sorted copy of int slice using bubble sort:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.