Introduction to Golang

  1. What Is Go (Golang)?



  2. Go favors composition over inheritance and explicit over implicit behavior.


  3. Key Features of Go



  4. Setting Up Your First Go Project



  5. Hello World in Go



  6. Basic Go Syntax Overview



  7. Go's Type System



  8. Concurrency: Goroutines and Channels



  9. Go's Standard Library



  10. Built-in Tooling




Your First Go Program

  1. Creating the Hello World Program



  2. Understanding the Program Structure



  3. Running the Program



  4. Building an Executable



  5. Understanding the Import Statement



  6. Variations of Hello World



  7. Adding Comments



  8. Formatting Your Code



  9. Understanding Module Initialization



  10. Running the Program with Arguments



  11. Creating Multiple Functions



  12. Cross-Compiling for Different Platforms




Go Variables and Data Types

  1. What Are Variables?



  2. Declaring Variables



  3. Zero Values



  4. Basic Data Types



  5. Integer Types Overview



  6. Special Integer Types



  7. Multiple Variable Declarations



  8. Constants



  9. Type Conversion



  10. Variable Scope



  11. Naming Conventions



  12. The Blank Identifier



  13. Variable Shadowing



  14. Pointers and Variables




Functions in Go

  1. What Are Functions?



  2. Basic Function Syntax



  3. Functions Without Return Values



  4. Functions With Parameters



  5. Multiple Return Values



  6. Named Return Values (it somehow reminds me of Pascal)



  7. Variadic Functions



  8. Anonymous Functions



  9. Functions as Values



  10. Closures



  11. The Defer Statement



  12. Recursive Functions



  13. Methods



  14. Function Type Declarations



  15. Init Function




Packages in Go

  1. What Are Packages?



  2. Package Declaration



  3. The Main Package



  4. Creating a Custom Package



  5. Importing Packages



  6. Package Visibility Rules



  7. Package Organization



  8. The Internal Package



  9. Go Modules



  10. Installing Third-Party Packages



  11. Standard Library Packages



  12. Package Documentation



  13. Package Initialization



  14. Vendor Directory



  15. Package Aliases and Naming Conflicts




Understanding Go Module Names and Project Naming

  1. What is a Module Path?



  2. The Structure of Module Paths



  3. Naming for Different Scenarios



  4. Common Domain Patterns



  5. Creating Your First Module
  6. # 1. Create project directory
    $ mkdir hello-world
    $ cd hello-world
    
    # 2. Initialize Go module with a name
    $ go mod init github.com/yourusername/hello-world
    
    # This creates go.mod file:
    # module github.com/yourusername/hello-world
    #
    # go 1.21
    
    # 3. Create your Go file
    $ cat > main.go << 'EOF'
    package main
    
    import "fmt"
    
    func main() {
        fmt.Println("Hello, World!")
    }
    EOF
    
    # 4. Run it
    $ go run main.go
    Hello, World!
    
    # 5. Build executable
    $ go build
    $ ./hello-world
    Hello, World!
    


  7. The go.mod File Explained



  8. Importing Your Own Packages



  9. Versioning in Module Names



  10. Working with Local Modules (Development)



  11. Best Practices




Control Flow in Go

  1. Go provides several control flow structures:


  2. If Statements



  3. If-Else Statements



  4. If With Initialization Statement



  5. Switch Statements



  6. Switch Without Expression



  7. Switch With Initialization



  8. Type Switch



  9. Fallthrough in Switch



  10. For Loop - Basic Form



  11. For Loop - While Style



  12. Infinite Loop



  13. Range-Based For Loop



  14. Break Statement



  15. Continue Statement



  16. Labels With Break and Continue



  17. Goto Statement



  18. Defer in Control Flow




Arrays and Slices in Go

  1. Understanding Arrays



  2. Declaring and Initializing Arrays



  3. Accessing and Modifying Array Elements



  4. Arrays Are Value Types



  5. Understanding Slices



  6. Declaring and Initializing Slices



  7. Slice Length and Capacity



  8. Slicing Operations



  9. Appending to Slices



  10. Copying Slices



  11. Removing Elements From Slices



  12. Multi-Dimensional Arrays and Slices



  13. Iterating Over Arrays and Slices



  14. Common Slice Operations



  15. Slice Tricks and Patterns



  16. Slice Internals and Memory




Variadic Functions in Go

  1. What Are Variadic Functions?



  2. Basic Syntax



  3. Variadic Parameters Are Slices

  4. func printInfo(names ...string) {
        // names is a []string slice
        fmt.Printf("Type: %T\n", names)      // Type: []string
        fmt.Printf("Length: %d\n", len(names))
        fmt.Printf("Values: %v\n", names)
    
        // Can use all slice operations
        if len(names) > 0 {
            fmt.Println("First:", names[0])
        }
    
        // Can iterate
        for i, name := range names {
            fmt.Printf("%d: %s\n", i, name)
        }
    }
    
    func main() {
        printInfo("Alice", "Bob", "Carol")
    }
    
    // Output:
    // Type: []string
    // Length: 3
    // Values: [Alice Bob Carol]
    // First: Alice
    // 0: Alice
    // 1: Bob
    // 2: Carol
    


  5. Passing Slices to Variadic Functions



  6. Advanced Patterns



  7. Performance Considerations




Type Aliases in Go

  1. What Are Type Aliases?



  2. Type Aliases in the Standard Library



  3. Type Aliases with Generics (Go 1.18+)



  4. Type Aliases and Reflection

  5. import "reflect"
    
    type MyString = string
    type MyStringType string
    
    func main() {
        var s1 MyString = "alias"
        var s2 MyStringType = "definition"
        var s3 string = "original"
    
        // Type alias: same reflect.Type as original
        t1 := reflect.TypeOf(s1)
        t3 := reflect.TypeOf(s3)
        fmt.Println(t1 == t3)  // true
        fmt.Println(t1.Name()) // string
    
        // Type definition: different reflect.Type
        t2 := reflect.TypeOf(s2)
        fmt.Println(t2 == t3)  // false
        fmt.Println(t2.Name()) // MyStringType
    }
    


  6. Limitations of Type Aliases




Maps in Go

  1. What Are Maps?



  2. Map Type Declaration



  3. Creating Maps



  4. Basic Map Operations



  5. Iterating Over Maps



  6. Sorting Map Keys for Consistent Order



  7. Maps Are Reference Types



  8. Zero Values and Nil Maps



  9. Maps with Complex Value Types



  10. Concurrent Access to Maps



  11. Comparing Maps




Strings in Go

  1. What Are Strings in Go?



  2. String Literals



  3. String Immutability



  4. UTF-8 Encoding and Runes



  5. String Indexing and Slicing



  6. String Concatenation



  7. Common String Operations (strings package)



  8. String Comparison



  9. Converting Between string, []byte, and []rune



  10. Iterating Over Strings



  11. String Formatting with fmt



  12. Regular Expressions with Strings



  13. String Performance Tips



  14. Common Mistakes and How to Avoid Them




Pointers in Go

  1. Pointer Syntax



  2. Pointers and Functions



  3. Pointers and Structs



  4. Nil Pointers



  5. Pointers and Arrays vs Slices




Structs in Go

  1. What Are Structs?



  2. Declaring Structs



  3. Creating Struct Instances



  4. Accessing and Modifying Fields



  5. Anonymous Structs



  6. Nested Structs



  7. Embedded Structs (Composition)



  8. Methods on Structs



  9. Struct Tags



  10. Comparing Structs



  11. Copying Structs



  12. Empty Structs



  13. Constructor Functions



  14. Common Patterns




Interfaces in Go

  1. What Are Interfaces?



  2. Defining Interfaces



  3. Implementing Interfaces



  4. Interface Values



  5. Type Assertions



  6. Type Switches



  7. Empty Interface and any



  8. Common Standard Library Interfaces



  9. Interface Composition



  10. Pointer vs Value Receivers



  11. Interface Design Guidelines




Concurrency in Go

  1. What Is Concurrency?



  2. Goroutines



  3. Channels



  4. Unbuffered vs Buffered Channels



  5. Channel Directions



  6. Closing Channels



  7. The Select Statement



  8. WaitGroups



  9. Mutexes



  10. Common Concurrency Patterns



  11. sync.Once



  12. Context Package



  13. Common Mistakes and How to Avoid Them



  14. Detecting Race Conditions



  15. Best Practices




Defer in Go

  1. What Is Defer?



  2. How Defer Works



  3. Common Use Cases



  4. Defer with Function Arguments



  5. Multiple Defer Statements



  6. Defer in Loops



  7. Defer and Return Values



  8. Defer with Panic and Recover



  9. Defer Performance



  10. Common Patterns



  11. Common Mistakes and How to Avoid Them



  12. Best Practices



  13. When NOT to Use Defer




Error Handling in Go

  1. Go's Error Philosophy



  2. The error Interface



  3. Creating Errors



  4. Error Wrapping (Go 1.13+)



  5. Checking Wrapped Errors: errors.Is



  6. Extracting Error Types: errors.As



  7. Custom Error Types



  8. Error Handling Patterns



  9. Panic and Recover



  10. Multiple Return Values



  11. Sentinel Errors



  12. Error Logging and Debugging



  13. Common Mistakes and How to Avoid Them



  14. Best Practices



  15. Testing Error Handling




First-Class Functions in Go

  1. What Are First-Class Functions?



  2. Function Types



  3. Functions as Parameters (Higher-Order Functions)



  4. Functions as Return Values



  5. Anonymous Functions and Function Literals



  6. Closures: Functions That Capture Variables



  7. Callback Functions



  8. Function Decorators and Middleware



  9. Method Values and Method Expressions



  10. Functions in Data Structures



  11. Variadic Functions with Functions



  12. Common Patterns and Idioms



  13. Common Mistakes and How to Avoid Them



  14. Best Practices




Reflection in Go

  1. What Is Reflection?



  2. The Core Types: reflect.Type and reflect.Value



  3. Type Information: reflect.Type



  4. Value Information: reflect.Value



  5. Setting Values



  6. Working with Structs



  7. Struct Tags



  8. Working with Slices and Arrays



  9. Working with Maps



  10. Calling Functions and Methods



  11. Creating New Values



  12. Type Comparison and Conversion



  13. Common Use Cases



  14. Performance Considerations



  15. Common Mistakes and How to Avoid Them



  16. Best Practices



  17. When to Use (and Not Use) Reflection




File Handling in Go

  1. File Basics



  2. Reading Files



  3. Writing Files



  4. File Open Modes and Flags



  5. File Information and Metadata



  6. Working with Directories



  7. File Operations: Copy, Move, Delete



  8. Temporary Files and Directories



  9. Reading and Writing Structured Data



  10. Seeking and Random Access



  11. File Locking and Concurrent Access



  12. Path Manipulation



  13. Common Patterns



  14. Common Mistakes and How to Avoid Them



  15. Best Practices