Exercise: Solve this exercise in Go with test cases.
Word count exerciseLabels: Beginner
Time to complete: 3-4 days
What will you learn:
- Basics of CLI building in Go, parsing CLI flags, cobra library
- File reading, listing files in a directory, dealing with a large number of files
- Writing table-driven tests
- Power of interfaces in Go (io.Reader interface)
- Using channels and goroutines to efficiently process multiple files in parallel, mutex, fan-in pattern for goroutines and channels.
How to evaluate your solution:
Actual Solution:
- Donβt look at the solution unless you have you. Otherwise, youβre not getting much value from the bootcamp.
I know what I am doing; stop patronising me.
- If you say so π€·, hereβs the sample implementation - https://github.com/one2nc/word-count
Resources:
- How to unit test code that reads from STDIN https://stackoverflow.com/questions/46365221/fill-os-stdin-for-function-that-reads-from-it
- How to handle Ctrl + d in Go https://pkg.go.dev/os/signal#example-Notify
- Writing command line applications in Go https://learning.oreilly.com/library/view/practical-go/9781119773818/c01.xhtml read Chapter 1 from this Practical Go book.
Β