golang 4.3 Mastering Go Maps: How to Store and Find Data with Key-Value Pairs TL;DR * What is a map? A collection of key:value pairs. You use a unique key (like a person's name) to find its corresponding value (like their phone number). * Why use a map? For incredibly fast data lookups. Instead of searching through a whole list, a map
golang 4.2 Go Slices: Shallow vs. Deep Copy by Example TL;DR * Assigning a slice to another (sliceB = sliceA) does not create a copy. Both variables will point to the exact same underlying data. * If you change an element in sliceB, the change will also appear in sliceA, leading to nasty bugs. 🐛 * To create a truly independent duplicate of a
golang 4.1 Go Arrays vs Slices: Pick Your Container TL;DR * Arrays have a fixed size you can never change. Think of them as a brick. * Slices are flexible and can grow or shrink. They are a view or a "slice" of an underlying array. * When you add items to a slice and it gets full, Go
golang 3.4 Use Go's defer for Easy Cleanup TL;DR * The defer keyword in Go schedules a function to run later. * This "deferred" function runs just before the surrounding function finishes. * If you have multiple defers, they run in reverse order (Last-In, First-Out). * It’s perfect for cleanup tasks, like making sure a file gets closed.
golang 3.3 Make Better Choices in Go with switch TL;DR * A switch statement is a clean way to handle multiple choices, like a tidier version of a long if-else chain. * It checks a single value or expression against a list of possible cases. * The default case is a safety net that runs if no other case matches. * A
golang 3.2 Repeat Code with Go's Three For Loops TL;DR * A for loop runs a block of code over and over again. * The traditional loop is for when you know the exact number of repetitions, like counting to ten. * The conditional loop is for when you need to repeat until something changes, like waiting for a download to
golang 3.1 Write Cleaner Go with if condition and Early Returns TL;DR * An if statement in Go can create a temporary variable that only exists right where you need it. * The best way to handle errors is to check for them immediately and stop right there if something is wrong. This is called an "early return." * This pattern
golang 2.4 Auto-Number Constants in Go with iota TL;DR * iota is Go's special keyword for creating sequences of numbers. Think of it as an automatic counter. * It starts at 0 and goes up by 1 for each constant you declare inside a const block. * It only works inside a const block. You can't
golang 2.3 Make Go Do Math: Operators & Type Conversion TL;DR * Operators are the action symbols like + (add) and > (greater than). * Go is very strict about types. You can't add a whole number (int) to a decimal number (float64) without telling it exactly what to do. * Type conversion is how you manually change data from one
golang 2.2 Golang Basic Data Types: int, float, bool, string TL;DR * Data types are labels that tell the computer what kind of information you're storing (e.g., a number, text, or a true/false value). * Use int for whole numbers, like 5 or -100. * Use float64 for decimal numbers, like 3.14 or 99.99. * Use bool
golang 2.1 Declare Go Variables with var, :=, and const TL;DR * Use var to be explicit about a variable, especially when you don't have a value for it yet. * Use := for a quick and clean way to declare and assign a variable inside a function. * Use const for values that you know will never, ever change, like
golang 1.5 Your First Go Program: The package main → func main Flow TL;DR * Every runnable Go program starts with package main. * The code that runs first is inside a special function called func main(). * The command go run <filename>.go compiles and executes your code. * We use built-in "packages" like fmt to do common things, like printing
golang 1.4 Structure Your Go Project Right(cmd, internal, pkg) TL;DR * Put your main, runnable programs in a /cmd directory. Think of this as the "On" switch for your application. * Hide private code that only your project should use inside an /internal directory. This is your secret workshop. * Place code that other projects can safely use in
golang 1.3 Manage Go Modules with go mod init & tidy TL;DR * go mod init is the first command you run. It creates a "shopping list" for your project's code ingredients. * A dependency is just code written by someone else that your project needs to work. * go get lets you add a new dependency or update
golang 1.2 How to use go tools(command): go run / build / test / fmt / vet TL;DR * go run: Instantly run your Go code without creating a separate file. Perfect for quick tests. * go build: Compile your code into a single, standalone program (an "executable") that you can run anywhere. * go fmt: Automatically clean up and format your code so it's
golang 1.1 Install Golang & Set Up Code Editor TL;DR * Install Go, the programming language itself. * Install VS Code, a free and popular code editor. * Add the Go extension to VS Code to give it Go superpowers. * Enable "Format on Save" in VS Code settings. * Now, your Go code will automatically get cleaned up every time