Go fundamentals
You learn Go, common in security and infrastructure tools, from scratch and build small, fast programs that handle errors explicitly.
Level 101 · 29 lessons · 24 practice labs
Lessons
Getting started
- The Go toolchain: go run, go build and a first program: You install Go and use go run and go build to run a first program and produce a single executable.
- Modules and packages: project layout with go mod: You create a module with go mod init, split code into packages and import other packages.
- Variables, constants and zero values: You use var, := and const and know which zero value each type starts with.
- Numeric types and conversion: You tell int, uint and float types apart, convert explicitly and account for overflow.
- Strings, bytes and runes: working with Unicode: You understand the difference between a string’s bytes and characters and process text with Turkish letters correctly.
- Operators and precedence: You use arithmetic, comparison and logical operators with attention to precedence.
- Short task: a small unit-conversion program
Control flow and data structures
- Conditions: if and switch: You write decisions with if short statements and switch, reducing needless nesting.
- Loops: the single for, range and labelled break: You use Go’s only loop, for, in its classic, conditional and range forms.
- Arrays and slices: You know the difference between a fixed array and a flexible slice and create and cut slices.
- Inside slices: capacity, append and shared memory: You understand why slices can change unexpectedly after append and take safe copies with copy.
- Maps: key-value data: You create maps, check key presence, delete entries and sort keys separately to iterate in order.
- Sorting: the sort and slices packages: You sort slices and lists of structs by your own criteria.
- Structs and field tags: You group related data in a struct, nest structs and see what field tags are for.
- Short task: count the most frequent words in a text
Functions, errors and interfaces
- Functions and multiple return values: You write functions that return several values and use named results and variadic arguments.
- Anonymous functions and closures: You pass functions around as values and write closures that capture outer variables.
- Pointers: value or address?: You tell a value’s copy from its address and modify a struct in place using functions that take pointers.
- Methods and interfaces: You attach methods to structs and use interfaces to treat different types through the same behaviour.
- Error values: error, errors.Is and errors.As: You handle errors as return values, wrap them and tell them apart by type.
- defer, panic and recover: You guarantee cleanup with defer and learn when panic is appropriate and how recover handles it.
- Short task: shared behaviour through an interface and a validator that returns errors
Real programs
- Reading and writing files: os and bufio: You read files line by line, write with buffering and close files using defer.
- Encoding and decoding JSON: encoding/json: You turn structs into JSON, read JSON into structs and check for unexpected fields.
- A command-line tool with the flag package: You write a small command-line program that takes flags and arguments and prints usage help.
- Unit tests with go test: You write table-driven tests, run them with go test and read the coverage figure.
- Input validation and bounded reading: You validate outside data and put an upper limit on how much you read.
- Short task: a tool that reads and validates a JSON config
Capstone
- Capstone: a Go tool that summarises a log file: You build a tool that takes flags, reads a log, writes event counts as JSON and comes with tests.
Practice labs
- Printing a temperature conversion table: Write a function that converts Celsius values to Fahrenheit and returns the result as a table formatted to one decimal.
- Filling zero values with defaults: Fill fields of a settings struct left at their zero value with defaults, using a pointer field to tell an intentional zero apart.
- Catching overflow in a size conversion: Fix a quota calculation that silently overflows when converting an int64 byte count to int32, returning an error at the limits and passing the random tests.
- Counting letters in Turkish text: Write two functions, one returning the rune count instead of byte length and one reversing text rune by rune.
- Producing a slug from a title: Use strings.Builder to lower-case a title, map Turkish letters and produce a hyphenated slug, collapsing consecutive separators.
- Truncating text without splitting a rune: Fix a truncation function that cuts at a byte limit and produces broken characters so it cuts at a valid UTF-8 boundary and also handles invalid input.
- Determining the shipping zone with switch: Write a function with a tagless switch that returns the shipping zone and fee from the first two digits of a postcode.
- Using a labelled break in a grid search: Write a search that leaves both loops at once with a labelled break on finding the first empty cell of a two-dimensional grid.
- Finding a stored-loop-variable-address bug: Find the discount code that stores the address of the range copy so updates are lost and fix it to update the slice elements in place.
- Filtering a slice in place: Write a function that removes negative readings from a slice without allocating new memory.
- Tracking capacity growth with append: Remove reallocations by giving capacity up front and show with testing.AllocsPerRun that the allocation count drops to zero.
- Curing corruption from a shared backing array: Fix paging code where appending to a sub-slice overwrites the original's data, using three-index slicing or a copy, and pass the random tests.
- Counting product quantities with a map: Compute total quantity per product from sales lines with a map and use the comma-ok idiom when querying a missing product.
- Sorting employees by several fields: Sort employees by department and then surname with slices.SortFunc so the result is the same on every run.
- Making a report that relies on map order stable: Make the output of a report whose row order changes on each run and breaks a test now and then stable by sorting keys, and fix JSON names with struct tags.
- Returning quotient and remainder together: Write a function that returns quotient, remainder and an error, giving an error value on division by zero.
- A sequence number generator with a closure: Produce a closure that takes a prefix and returns an id with an increasing number on each call and test that two generators count independently.
- Finding an update lost in a value receiver: Find the value and pointer receiver mix-up in an account type whose balance updates vanish, make it consistent and make a nil-receiver call safe too.
- Writing a Stringer for a money type: Add a String method to a money type held in kuruş, printing with a thousands separator and two decimals.
- Telling errors apart with errors.Is and errors.As: Write a handler that recognises not-found with errors.Is and a validation error carrying a field name with errors.As among wrapped errors.
- Containing a panicking plugin with recover: Fix a runner that brings the whole program down when a plugin panics using defer and recover, turning the panic into an error and showing open files are closed.
- Counting lines and words in a file: Write a function that computes a file's line and word counts with bufio.Scanner and closes the file with defer.
- Reading JSON settings and overriding with flags: Decode a JSON settings file rejecting unknown fields, override it with flag values and report an invalid port with a clear error.
- Hardening input with bounded reads and table tests: Bound a loader that reads the whole file into memory with io.LimitReader, reject overlong lines and cover the edge cases with table-driven tests.
About this course
You learn Go, common in security and infrastructure tools, from scratch and build small, fast programs that handle errors explicitly.
What you will learn
- Getting started
- Control flow and data structures
- Functions, errors and interfaces
- Real programs
- Capstone
Prerequisites
No prior knowledge is needed; the course starts from zero.
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 beginner level; every term is explained where it first appears.
- 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.