Go practice
In each exercise you solve a small but real problem in Go and make a habit of writing code that passes its tests and handles errors properly.
Level 201 · 17 lessons · 18 practice labs
Lessons
Strings and collections
- Exercise: cleaning and normalising messy text
- Exercise: totals and averages from a CSV file
- Exercise: grouping records with a map
- Exercise: removing duplicates and sorting stably
- Short task: find the difference between two inventory lists
Errors, interfaces and tests
- Exercise: wrapping errors with context
- Exercise: one interface for in-memory and file storage
- Exercise: a validator with table-driven tests
- Exercise: Filter and Map helpers with generics
- Short task: a package that validates IP and CIDR input
Files, time and concurrency
- Exercise: finding large files in a directory tree
- Exercise: parsing timestamps in different formats
- Exercise: a race-free concurrent counter
- Exercise: running jobs at a limited rate per second
- Exercise: transforming and filtering a JSON stream
- Short task: a tail-like tool that follows a growing log file
Capstone
- Capstone: an audit report from a user and permission dump
Practice labs
- Bringing a phone list to one format: Convert phone numbers written in different ways to one format and return the invalid ones in a separate list.
- Deriving branch averages from a CSV: Read Ayçiçeği Gıda's sales file with encoding/csv, compute total and average per branch and report bad rows with line numbers.
- Comparing two inventory dumps in a stable order: Find added, removed and changed records between an old and a new inventory, drop duplicates and produce output in a stable order.
- Wrapping an error with context: Wrap file read errors with %w adding which file and which step and test that errors.Is still works.
- Two storage backends behind one interface: Put in-memory and file-based stores behind one interface and run both through the same test suite.
- Grouping and reducing helpers with generics: Write type-parameterised GroupBy and Reduce helpers, choose the constraints properly and replace three existing copy-paste functions with them.
- Table-testing a username validator: Write a validator that checks length and allowed-character rules together with its table-driven tests.
- Checking whether an IP is inside a network range: Use net/netip to return whether an address falls into one of the allowed ranges and give a meaningful error for invalid input.
- Writing an IP and CIDR validation package: Write a package that validates IPv4, IPv6 and ranges and detects overlapping networks, delivered with example functions and tests covering the edge cases.
- Finding the largest files in a directory tree: Walk a tree with filepath.WalkDir and return the ten largest files in size order.
- Parsing timestamps in different formats: Try three timestamp formats in turn, convert to UTC and report with an error anything matching none of them.
- Following a growing log file: Write a tool that follows lines appended to a file, restarts from the beginning when the file is truncated or replaced and misses no line.
- A race-free concurrent counter: Write a counter incremented by a hundred goroutines with atomic and verify with -race that the result is exact on every run.
- Running jobs at a limited rate per second: Write a scheduler that starts at most five jobs per second with time.Ticker and show it stops the ticker when cancelled.
- Filtering a large JSON stream memory-efficiently: Read a huge JSON array item by item with json.Decoder, transform and write matching items and measure that memory use stays independent of input size.
- A per-customer rate limit with bursts: Write a limiter with a per-second limit and a short burst allowance for each customer, cleaning up entries for customers not seen for a long time and passing the race detector.
- Computing the time left until a deadline: Write a function that prints the time left until a given deadline in days and hours, showing the overdue time for past dates and taking the current time as a parameter.
- Finding the next run time in a time zone: Compute the next run time of a job that runs daily at the same local time in a given time zone; the tests check the skipped and repeated hours at daylight-saving changes.
About this course
In each exercise you solve a small but real problem in Go and make a habit of writing code that passes its tests and handles errors properly.
What you will learn
- Strings and collections
- Errors, interfaces and tests
- Files, time and concurrency
- Capstone
Prerequisites
Finishing the level 101 courses of the same path, or knowing those topics, is enough.
Lab environment
Lessons run in your own Kali Linux terminal that opens in the browser. Nothing to install; the lab starts clean in every lesson.
Frequently asked questions
- Is this course right for my level?
- The course is at level 201; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.