Exercise: Solve this exercise in Go with test cases.
Grep exerciseLabels: Intermediate
Time to complete: 4-5 days
What will you learn:
- Basics of CLI building in Go, parsing CLI flags, cobra library
- File reading and writing, 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 patronizing me.
- If you say so ๐คท, hereโs the sample implementation - https://github.com/ishan-p/go-grep
Resources:
- โถ๏ธ Building Grep using Test driven development in Go on One2N YouTube channel (itโs a long playlist, watch at 2x speed). This playlist contains a live code walkthrough where we build Grep in Go using Test Driven Development. https://www.youtube.com/playlist?list=PLMrAF6rR54XoimthOUqXkPXlIAVuE4N0i. If you find the videos too long and prefer a text version summary, see below:
- How to unit test code that reads from STDIN https://stackoverflow.com/questions/46365221/fill-os-stdin-for-function-that-reads-from-it
- 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.
ย