- Create an executable go program in directory
01_fib/USERNAME - 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.
- Create an executable go program in directory
02_bubble/USERNAME - Write a function that returns a sorted copy of
intslicesusing 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
- Create an executable go program in directory
03_letters/USERNAME - 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
- 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]
- Create an executable go program in directory
05_stringer/USERNAME - Make the
IPAddrtype implementfmt.Stringerto print the address as a dotted quad - Find hints at tour of go exercise: stringers
- Call
fmt.Println(IPAddr{127, 0, 0, 1})inmainto print:
127.0.0.1
- Create an executable go program in directory
06_puppy/USERNAME(see hints) - Implement a
Puppystruct containingID,Breed,Colour,Value - Create
Storerinterface with crud methods forPuppy - Write a
MapStoreimplementation ofStorerbacked by amap - Write a
SyncStoreimplementation ofStorerbacked by a sync.Map - Keep all implementation files in the same folder and in package
main - Test against the
Storerinterface and run in suite with both implementations
-
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
Errorwith fieldsMessageandCode -
Extend the
Storerinterface for all methods to also returnerror -
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
Storerimplementation using leveldb
- Copy the CRUD puppy from upstream master
07_errors/USERNAME - Create directory
08_project/USERNAMEcontaining
├── 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
- Create directory
09_json/USERNAMEcontaining a copy of upstream master08_project/USERNAME - Add JSON tags to puppy data type
- Test marshalling and unmarshalling using require.JSONEq
- Add command line flag
-d FILEwith long form--data FILEusing kingpin.v2 - FILE should contain an array of puppies in JSON format. Parse this file and store its contents.
- Create directory
10_rest/USERNAMEcontaining a copy of upstream master09_json/USERNAME - Add file
pkg/puppy/rest.goimplementing:
GET /api/puppy/{id}
POST /api/puppy/ Payload: Puppy JSON without ID
PUT /api/puppy/{id} Payload: Puppy JSON without ID
DELETE /api/puppy/{id}
- Use net/http/httptest for testing
- Add flag
-p PORTwith long flag--port PORTto command line flags - Add flag
-s STOREwith long flag--store STOREwith accepted values:
map, sync, db
Document the API in README.md
- Create directory
11_notify/USERNAMEcontaining a copy of upstream master10_rest/USERNAME - Create
cmd/lostpuppy-service/main.gorunning single endpoint:
POST /api/lostpuppy/ Payload: { id: PUPPY_ID }
This stubbed endpoint returns with 2 second delay:
HTTP status 201 for even IDs
HTTP status 500 for odd IDs
Update Puppy Delete method to notify lostpuppy-service in a goroutine and log response code asynchronously.