Here is a 100-step roadmap of exercises, categorized by "Belt Level," to take you from zero to architectural hero.
Phase 1: The White Belt (Syntax & Basics)
Focus: Getting comfortable with the "Go way" of doing simple things.
- Hello, Go: Print "Hello, World" and run it via go run.
- Variables: Declare variables using var vs := for all basic types.
- Constants: Create typed and untyped constants.
- The For Loop: Write a loop that counts from 1 to 100.
- FizzBuzz: The classicâÂÂif divisible by 3 (Fizz), 5 (Buzz), or both.
- Conditionals: Use if/else with a short statement (e.g., if count := 10; count > 5).
- Switch Basics: A switch statement to identify the day of the week.
- Basic Functions: Create a function that takes two ints and returns the sum.
- Multiple Returns: A function that returns both a quotient and a remainder.
- Named Returns: Rewrite the previous function using named return parameters.
- Pointers 101: Write a function that increments an integer using a pointer.
- The nil Check: Write a function that returns an error if a pointer is nil.
- Arrays: Declare an array of 5 strings and print the 3rd element.
- Slices: Create a slice from an array.
- Append: Use append to dynamically grow a slice of integers.
- Slice Capacity: Use len() and cap() to watch a slice grow in a loop.
- Range: Use for range to iterate over a slice and print indices and values.
- Maps: Create a map of state codes to state names (e.g., "NY": "New York").
- Map Lookup: Check if a key exists in a map using the "comma ok" idiom.
- Deleting: Remove an entry from a map.
Phase 2: The Yellow Belt (Data & Control)
Focus: Managing data structures and error handling.
- Structs: Define a User struct with Name, Email, and Age.
- Embedded Structs: Create an Admin struct that embeds the User struct.
- Methods: Add a Greet() method to your User struct.
- Pointer Receivers: Add a method UpdateEmail() that modifies the struct.
- JSON Encoding: Convert a struct instance into a JSON string.
- JSON Decoding: Parse a JSON string into a Go struct.
- Custom Errors: Create a custom error type that implements the error interface.
- Defer: Write a function that opens a file and uses defer to close it.
- Variadic Functions: Create a function that sums an arbitrary number of integers.
- Slicing Slices: Take a slice and create a "sub-slice" using [low:high].
- Make vs New: Write a script demonstrating the difference between make() and new().
- String Manipulation: Use the strings package to split a CSV line.
- String Building: Use strings.Builder to efficiently join 1,000 strings.
- Byte Slices: Convert a string to a []byte and back.
- Type Casting: Convert an int to a float64 and calculate a percentage.
- Blank Identifier: Use _ to ignore specific return values from a function.
- Sorting: Sort a slice of integers using the sort package.
- Custom Sorting: Sort a slice of User structs by Age.
- Math/Rand: Generate a random number between 1 and 100.
- Time: Print the current time in "2006-01-02" format.
Phase 3: The Blue Belt (Interfaces & Engineering)
Focus: Decoupling code and writing testable logic.
The Interface: Define a Shape interface with an Area() method.
Implementing Interfaces: Create Circle and Square structs that satisfy Shape.
Empty Interface: Write a function that accepts interface{} and uses a type switch.
Type Assertions: Manually assert that an interface value is a specific struct.
Dependency Injection: Pass an interface into a function instead of a concrete struct.
Reader Interface: Use io.Reader to read data from a string.
Writer Interface: Use io.Writer to write data to a buffer.
Decorators: Wrap a Reader to count how many bytes are read.
Mocking: Write a unit test for a function by passing in a "mock" interface.
Table-Driven Tests: Write a test suite for a calculator using a slice of anonymous structs.
Unit Testing: Use the testing package to test a string reversal function.
Benchmarking: Use go test -bench to measure the speed of a function.
Project Layout: Organize a project into /cmd and /internal folders.
Go Modules: Initialize a module and add a 3rd party dependency (e.g., logrus).
Environment Variables: Use os.Getenv to configure a mock database URL.
Flag Package: Create a CLI tool that accepts a --name argument.
I/O Utility: Read an entire file into memory using os.ReadFile.
Streaming I/O: Read a massive file line-by-line using bufio.Scanner.
Regular Expressions: Validate an email address using the regexp package.
Log Levels: Implement a logger that distinguishes between Info, Warning, and Error.
Phase 4: The Brown Belt (Concurrency)
Focus: Master the "Go" in Golang-Goroutines and Channels.
- Goroutine Basics: Launch a function using the go keyword.
- WaitGroup: Use sync.WaitGroup to wait for three goroutines to finish.
- Unbuffered Channels: Send a string from one goroutine to another.
- Buffered Channels: Create a channel with a capacity of 3 and fill it without blocking.
- Channel Closing: Close a channel and detect it on the receiving end.
- Select Statement: Use select to handle multiple channel inputs.
- Timeouts: Use select with time.After to timeout a slow operation.
- The Worker Pool: Create 5 workers that process jobs from a shared channel.
- Mutex: Use sync.Mutex to prevent a race condition when incrementing a counter.
- RWMutex: Use sync.RWMutex to allow multiple readers but one writer.
- Atomic Operations: Use sync/atomic for high-performance counter increments.
- The Race Detector: Run a program with go run -race to find a bug.
- Once: Use sync.Once to ensure a setup function only runs one time.
- Directional Channels: Write a function that only accepts a "read-only" channel (<-chan).
- Pipeline Pattern: Connect three channels where each stage transforms the data.
- Fan-Out: Send one piece of data to multiple worker goroutines.
- Fan-In: Consolidate results from multiple channels into a single output channel.
- Context Basics: Use context.Background() to pass metadata.
- Context Cancellation: Cancel a long-running goroutine using context.WithCancel.
- Context Deadlines: Automatically stop a database query after 500ms using WithTimeout.
Phase 5: The Black Belt (Senior/Architect)Focus: Production-grade systems, performance, and internal mechanics.
- HTTP Server: Build a basic REST API using net/http.
- Middleware: Create an HTTP middleware that logs the execution time of every request.
- Graceful Shutdown: Capture os.Signal to shut down a server without dropping active connections.
- SQL Integration: Use database/sql to query a Postgres or SQLite database.
- Prepared Statements: Prevent SQL injection using placeholders.
- Database Transactions: Implement a multi-step "Balance Transfer" with Rollback logic.
- Reflection: Write a function that prints the field names of any struct passed to it.
- The Unsafe Package: Access a struct's private fields (just to see how it works).
- Generics: Write a generic Map function that works for any slice type.
- Functional Options: Implement a "NewServer" constructor using the Functional Options pattern.
- CGO: Call a simple C function from your Go code.
- Profiling: Use pprof to identify a CPU bottleneck in a loop.
- Memory Profiling: Identify a memory leak using go tool pprof --alloc_objects.
- Embedding Static Files: Use //go:embed to include a text file in your binary.
- Custom Marshaller: Implement MarshalJSON for a struct to hide sensitive fields.
- The Circuit Breaker: Implement a pattern that stops calling a failing API after X errors.
- Rate Limiting: Use golang.org/x/time/rate to limit API requests per second.
- Plugin System: Build a system where Go can load .so files at runtime.
- The Scheduler: Write a technical blog post (or notes) explaining how M:P:N scheduling works in Go.
- The Microservice: Build a small service that communicates via gRPC and Protobuf.
How to approach this
Don't try to do all 100 in a weekend. Go is deceptive; it looks simple, but the "Senior" part comes from understanding why we prefer composition over inheritance and channels over shared memory.
by Gemini