Welcome to Go Training! This repository is designed to help beginners learn Go programming from scratch with clear, easy-to-follow examples.
# Using Homebrew
brew install go
# Or download from official website
# Visit: https://go.dev/dl/# Download and install
wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.21.5.linux-amd64.tar.gz
# Add to PATH (add to ~/.bashrc or ~/.zshrc)
export PATH=$PATH:/usr/local/go/bin- Download the installer from https://go.dev/dl/
- Run the MSI installer
- Follow the installation wizard
go versionYou should see output like: go version go1.21.5 darwin/amd64
# Check your GOPATH
go env GOPATH
# Create a workspace directory (if needed)
mkdir -p ~/go/src-
Navigate to any example folder
-
Run the program:
go run main.go
-
Build an executable:
go build main.go ./main
-
example1-hello-world - Your First Go Program
- Basic program structure
- Package declaration
- Import statements
- Main function
- Print to console
-
example2-variables-types - Variables and Data Types
- Variable declaration
- Basic data types (int, string, bool, float)
- Type inference
- Constants
- Zero values
-
example3-control-flow - Control Flow
- If/else statements
- Switch statements
- For loops
- Break and continue
-
example4-functions - Functions
- Function declaration
- Parameters and return values
- Multiple return values
- Named return values
- Variadic functions
-
example5-arrays-slices - Arrays and Slices
- Array declaration and usage
- Slice basics
- Slice operations (append, copy)
- Slice iteration
-
example6-maps - Maps (Hash Tables)
- Map declaration
- Adding and retrieving values
- Checking key existence
- Iterating over maps
- Deleting keys
-
example7-structs - Structs
- Struct definition
- Creating struct instances
- Struct fields
- Struct methods
- Embedded structs
-
example8-pointers - Pointers
- Pointer basics
- Address operator (&)
- Dereference operator (*)
- Pointers with functions
- Pointers with structs
-
example9-context - Context Package
- What is context and why it matters
- Context cancellation
- Context with timeout
- Context with deadline
- Passing values through context
- Real-world use cases (HTTP, database, goroutines)
- Best practices and patterns
-
example10-clean-architecture - Clean Architecture
- Production-ready REST API
- Entity, DTO, Repository, UseCase, Handler layers
- Dependency injection
- Interface-based design
- Unit testing with mocks
- Idiomatic Go patterns
- example11-goroutines - Advanced Goroutines & Concurrency
- Goroutines and concurrent execution
- WaitGroup synchronization
- Channels (buffered vs unbuffered)
- Worker Pool pattern
- Fan-Out Fan-In pattern
- Pipeline pattern
- Graceful shutdown
- Retry logic and rate limiting
- Reference: go-routine-patterns
- Start from example1 and work your way through sequentially
- Read the README in each example folder for detailed explanations
- Run the code to see it in action
- Modify the code to experiment and learn
- Complete the exercises (if provided) to reinforce learning
- π‘ Type the code yourself instead of copy-pasting
- π Experiment by changing values and seeing what happens
- π Take notes on concepts that are new to you
- π Debug errors - they're great learning opportunities
- π Review previous examples if you get stuck
Start Here
β
example1: Hello World (Basics)
β
example2: Variables & Types (Data)
β
example3: Control Flow (Logic)
β
example4: Functions (Organization)
β
example5: Arrays & Slices (Collections)
β
example6: Maps (Key-Value Storage)
β
example7: Structs (Custom Types)
β
example8: Pointers (Memory)
β
example9: Context (Cancellation & Timeouts)
β
example10: Clean Architecture (Production Patterns)
β
example11: Goroutines (Concurrency Patterns)
β
Keep Learning! π
- Go Official Website
- Go Documentation
- Go Tour - Interactive tutorial
- Effective Go - Best practices
- Go by Example
- Exercism Go Track
- LeetCode - Practice algorithms
Found a bug or have a suggestion? Feel free to open an issue or submit a pull request!
This project is open source and available for educational purposes.
Happy Learning! π
Remember: Everyone starts as a beginner. Take your time, practice regularly, and don't be afraid to make mistakes!