A practical, beginner-friendly Go walkthrough created by Amit K. Jangir.
This repository is a compact learning map for Go fundamentals. Each folder focuses on one concept, with small runnable examples and comments written to explain the idea without overwhelming the reader.
Each concept folder also has its own README.md with the files to run, the main ideas to practice, and useful predefined functions or commands for that topic.
- Variables, constants, and basic printing
- Conditions, switch statements, and type switches
- Arrays, slices, maps, and range loops
- Functions, multiple returns, variadic functions, and closures
- Structs, embedded structs, methods, and pointer receivers
- Interfaces and behavior-based design
- Pointers and pass-by-value behavior
- File and folder handling with the
os,io, andpath/filepathpackages - Generics with typed functions and a generic stack
- Goroutines, channels, WaitGroups, and mutexes
- Enum-style typed constants with
iota - Local packages, modules,
go.mod,go.sum, and third-party dependencies - Error handling, custom errors, panic, and recover
- Testing with table-driven tests and benchmarks
- HTTP servers and handlers
- JSON encoding and decoding
- Context for cancellations, timeouts, and request-scoped values
- Defer for resource cleanup and timing
.
|-- array/ # Arrays, slices, maps, and range
|-- channels/ # Channel basics, buffering, done signals, and select
|-- conditions/ # if/else and switch examples
|-- context/ # Context for cancellations, timeouts, and request-scoped values
|-- defer/ # Deferred function execution for cleanup and timing
|-- enums/ # Enum-style constants with iota
|-- error_handlings/ # Error handling, custom errors, panic, and recover
|-- files/ # File reading, writing, renaming, deleting, and folders
|-- functions/ # Functions, closures, variadic params, function values
|-- generics/ # Generic functions and generic types
|-- goroutines/ # Concurrent execution and WaitGroups
|-- http/ # HTTP servers and handlers
|-- interface/ # Interface-driven payment gateway example
|-- json/ # JSON encoding and decoding
|-- loops/ # for loops, break, and continue
|-- mutex/ # Race-condition-safe shared state
|-- packages/ # Local packages, exported names, and dependencies
|-- pointer/ # Pointers and value updates
|-- struct/ # Structs, methods, embedding, constructors
|-- testing/ # Unit testing, table-driven tests, and benchmarks
|-- variables/ # Variables, constants, and simple expressions
|-- go.mod # Module name and dependency requirements
|-- go.sum # Dependency checksums
`-- main.go # Small root entry point
Install Go, then clone the repository and run any sample file directly:
go run variables/variables.go
go run array/slice.go
go run goroutines/goroutines.go
go run packages/main.go
go run error_handlings/basic_error_handling.go
go run http/server.go
go run json/json.go
go run context/context.go
go run defer/defer.goMost concept files are standalone package main examples. Run files one at a time instead of running an entire folder, because some folders contain multiple standalone examples.
For quick notes about a topic, open the README.md inside that folder before running its examples.
The packages/ example imports local packages and the third-party github.com/fatih/color package, so run it from the repository root:
go run packages/main.goThe files/ example can be run from the root or from inside the files folder:
go run files/files.go
cd files && go run files.goThe testing/ folder contains test files that are run with go test:
go test -v ./testing/
go test -bench=. ./testing/The http/ example starts a web server that you can access in your browser:
go run http/server.go
# Then visit http://localhost:8080/Use Go 1.21 or newer.
Some examples use modern standard-library helpers such as slices, maps, and the clear built-in.
- Start with
variables/andconditions/. - Move to
loops/,array/, andfunctions/. - Learn
pointer/,struct/,interface/, andfiles/. - Explore
packages/to understand modules, imports, exported names, and dependencies. - Learn
error_handlings/for Go's explicit error handling approach. - Practice
defer/for resource cleanup and timing. - Explore
context/for cancellations, timeouts, and request-scoped values. - Learn
json/for encoding and decoding JSON data. - Build web servers with
http/. - Write tests with
testing/. - Finish with
generics/,goroutines/,channels/, andmutex/.
This project uses Go modules:
go.moddefines the module path and required dependencies.go.sumstores checksums for downloaded dependencies.go mod tidycleans unused dependencies and adds missing ones after import changes.
The packages/ example demonstrates both local imports and a small third-party package.
The goal is to help new Go learners get a quick but useful overview of the language. The examples are intentionally small, readable, and commented so readers can focus on one concept at a time.
Created and maintained by Amit K. Jangir.
If this repository helps you, consider starring it and sharing it with someone starting their Go journey.