Skip to content

Go Tutorials

In this tutorial, you'll learn about Go Tutorials. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

Go is a statically typed, compiled programming language for building efficient, reliable software at scale. It powers Docker, Kubernetes, and cloud-native infrastructure.

1. What is Go?
History, simplicity, concurrency, use cases
2. Installation & Setup
go install, GOPATH, modules, first program
3. Hello World
package main, func main, fmt, go run
4. Variables
var, :=, types, zero values, constants
5. Control Flow
if/else, for, switch, defer
6. Functions
func, returns, multiple returns, named returns
7. Arrays & Slices
Fixed arrays, slice, append, make, copy
8. Maps & Structs
map, struct, tags, zero values
9. Pointers
&, *, nil, new, pointer receivers
10. Methods
Receiver types, value vs pointer, method sets
11. Interfaces
Implicit satisfaction, empty interface, type assertion
12. Embedding
Struct embedding, interface embedding, composition
13. Error Handling
error interface, errors.New, fmt.Errorf
14. Panics
panic, recover, defer stack, error vs panic
15. Packages & Modules
package, export, go mod, import paths
16. Testing
testing package, table tests, coverage, bench
17. Goroutines
go keyword, goroutine lifecycle, GOMAXPROCS
18. Channels
make(chan), <-, send/receive, buffered
19. Select
select, default, timeout, nil channels
20. WaitGroups
sync.WaitGroup, Add/Done/Wait

Advanced & Projects

21. Mutexes
sync.Mutex, RWMutex, atomic, race detector
22. Context
context.Background, WithCancel, WithTimeout
23. Worker Pools
Fan-out, fan-in, pipeline pattern
24. Concurrency Patterns
Generator, tee, bridge, or-done
25. File I/O
os, io, bufio, file operations
26. JSON
json.Marshal, Unmarshal, Encoder, tags
27. HTTP Server
http.Handler, ServeMux, middleware
28. HTTP Client
http.Client, Transport, timeouts
29. Database SQL
database/sql, rows, prepared statements
30. Templates
text/template, html/template, template funcs
31. Flag & Cobra
flag, cobra CLI, viper config
32. Logging
log, log/slog, structured logging
33. HTTP Advanced
Routing, middleware, context in handlers
34. REST API
encoding/json, REST patterns, versioning
35. Gin & Echo
Gin/Echo frameworks, routers, middleware
36. GORM
ORM, models, migrations, associations
37. Authentication
JWT, bcrypt, OAuth2, sessions
38. GraphQL
gqlgen, resolvers, schemas
39. Generics
Type parameters, constraints, ~ operator
40. Reflection
reflect package, tags, field iteration
41. CGo
C interop, #include, build tags
42. Profiling
pprof, trace, benchstat, memory profiling
43. Modules Advanced
Workspaces, replace, versioning, proxies
44. Wire & Protobuf
Google Wire DI, Protocol Buffers, protoc
45. Project: CLI
Build a CLI with cobra
46. Project: REST API
Build a REST API with Gin + GORM
47. Project: Scraper
Build a concurrent web scraper
48. Project: Chat
Build a WebSocket chat server
49. Project: Microservice
Build a microservice with gRPC
50. Deployment
Docker, multi-stage builds, CI/CD

Published Topics

What is Go? History, Simplicity and Concurrency Explained

Go is a statically typed compiled language created at Google for building efficient, reliable software at scale with built-in concurrency and simple syntax.

✓ Live

Go Installation Guide — Set Up Go on Linux macOS and Windows

Learn how to install Go using go install, configure GOPATH and modules, and set up your development environment for Go programming.

✓ Live

Go Hello World — Package main func main and go run Explained

Go's hello world demonstrates package main for executables, func main as the entry point, the fmt package for output, and go run for quick execution.

✓ Live

Go Variables and Data Types — var := Zero Values and Constants Explained

Go variables use var or := for type inference with static typing, zero values for automatic initialization, and constants with specific types.

✓ Live

Go Control Flow — if else for switch and defer Explained

Go control flow includes if/else with initialization statements, for as the only loop keyword, switch with expressionless cases, and defer for cleanup.

✓ Live

Go Functions — func Multiple Returns Named Returns and Variadic Parameters

Go functions defined with func support multiple return values, named returns for documentation, variadic parameters with ..., and first-class function values.

✓ Live

Go Arrays and Slices — Fixed Arrays append make and copy Explained

Go arrays have fixed size at compile time while slices are dynamically-sized views backed by arrays with append, make, and copy for flexible collection management.

✓ Live

Go Maps and Structs — map struct Tags and Zero Values Explained

Go maps provide key-value storage with O(1) lookup, structs group related fields with optional tags for serialization, and both have zero values for safe initialization.

✓ Live

Go Pointers — & * nil new and Pointer Receivers Explained

Go pointers hold memory addresses using & for address-of and * for dereference, with nil for safe zero values and pointer receivers for method modification.

✓ Live

Go Methods — Value Receivers Pointer Receivers and Method Sets Explained

Go methods are functions with a receiver argument that can be a value or pointer type, enabling object-oriented behavior through method sets and interface satisfaction.

✓ Live

Go Interfaces — Implicit Satisfaction Type Assertions and Empty Interface Explained

Go interfaces define behavior through method sets with implicit satisfaction, enabling polymorphism through type assertions, type switches, and the empty interface for unknown types.

✓ Live

Go Embedding — Struct Embedding Interface Embedding and Method Promotion Explained

Go embedding allows one struct or interface to include another, promoting its fields and methods to the embedding type for composition-based reuse without inheritance.

✓ Live

Go Error Handling — Error Interface Error Wrapping and Sentinel Errors Explained

Go error handling uses the error interface with explicit return values, %w wrapping for error chains, errors.Is and errors.As for inspection, and sentinel errors for predefined failures.

✓ Live

Go Panic and Recover — defer panic recover and Safe Error Handling Explained

Go panic and recover provide error handling for exceptional conditions with defer for cleanup, panic for unrecoverable errors, and recover for catching panics in goroutines.

✓ Live

Go Packages and Modules — go.mod, Import Paths and Package Visibility Explained

Go packages organize code with exports (capitalized) and unexports (lowercase), while modules defined in go.mod manage dependencies, versioning, and import paths.

✓ Live

Go Testing — Table Tests Benchmarks Coverage and Test Suites Explained

Go testing uses the testing package with t *testing.T for unit tests, t *testing.B for benchmarks, table-driven tests for multiple cases, and go test -cover for coverage analysis.

✓ Live

Go Goroutines — go Keyword WaitGroups and Concurrent Execution Explained

Go goroutines are lightweight threads started with the go keyword, enabling concurrent execution with WaitGroups for synchronization and channel communication.

✓ Live

Go Channels — Unbuffered Buffered Range and Directional Channels Explained

Go channels provide typed communication between goroutines with unbuffered for synchronization, buffered for async, range for iteration, and directional types for type safety.

✓ Live

Go Select — Multiplexing Channel Operations with Select Statement

Go select statement multiplexes channel operations with case branches for non-blocking sends, receives, timeouts, and default cases.

✓ Live

Go WaitGroups — Synchronizing Goroutines with sync.WaitGroup

Go sync.WaitGroup synchronizes goroutine completion with Add, Done, and Wait methods for coordinating parallel work.

✓ Live

Go Mutexes — Protecting Shared State with sync.Mutex and sync.RWMutex

Go sync.Mutex and sync.RWMutex protect shared state in concurrent programs with Lock/Unlock for exclusive access and RLock/RUnlock for read sharing.

✓ Live

Go Context — Cancellation, Deadlines, and Values with context.Context

Go context.Context propagates cancellation signals, deadlines, and request-scoped values across API boundaries and goroutine hierarchies.

✓ Live

Go Worker Pools — Managing Concurrent Work with Worker Goroutines

Go worker pools manage concurrent work using a fixed number of goroutines consuming jobs from a channel with results collected via sync.WaitGroup.

✓ Live

Go Concurrency Patterns — Pipeline, Fan-Out/In, Generator, and Error Handling

Go concurrency patterns include pipelines for streaming data, fan-out/fan-in for parallelism, generators for lazy sequences, and errgroups for error handling.

✓ Live

Go File I/O — Reading and Writing Files with os, bufio, ioutil, and io Package

Go file I/O uses os.File for low-level operations, bufio for buffered reading/writing, io package for streams, and os.ReadFile/WriteFile for simplicity.

✓ Live

Go JSON — Encoding and Decoding JSON with encoding/json and Struct Tags

Go JSON handling uses encoding/json for Marshal/Unmarshal with struct tags for field mapping and custom marshaling for complex data.

✓ Live

Go HTTP Servers — Building Web Servers with net/http Package and Handlers

Go net/http package provides HTTP server capabilities with Handler interface, ServeMux for routing, and middleware for cross-cutting concerns.

✓ Live

Go HTTP Client — Making HTTP Requests with net/http Client and Transport

Go http.Client makes HTTP requests with configurable Transport, timeouts, and connection pooling for efficient API communication.

✓ Live

Go Database SQL — SQL Database Operations with database/sql and Drivers

Go database/sql package provides generic SQL database interface with connection pooling, prepared statements, transactions, and row scanning.

✓ Live

Go GORM — ORM for Go with GORM Library and Database Migrations

Go GORM provides an ORM with automatic migrations, association management, query building, and hooks for PostgreSQL, MySQL, and SQLite.

✓ Live

Go Generics — Type Parameters for Reusable Go Functions and Types

Go generics provide type parameters for functions and types with constraint interfaces allowing type-safe reusable code without runtime type assertions.

✓ Live

Go Reflection — Runtime Type Inspection and Manipulation with reflect Package

Go reflect package enables runtime type inspection with TypeOf, ValueOf, and method calling for dynamic programming patterns.

✓ Live

Go CGo — Calling C Code from Go with cgo and Build Tags

Go CGo enables C code integration with import "C" directive, C type mapping, memory management, and build tag conditional compilation.

✓ Live

Go Advanced Testing — Table-Driven Tests, Fuzzing, Test Coverage, and Benchmarks

Go advanced testing includes table-driven tests, fuzzing with testing.F, test coverage analysis, and subtest/subbenchmark organization.

✓ Live

Go Benchmarking — Performance Testing with testing.B and Benchmark Functions

Go benchmarking measures performance with testing.B for timing, b.N for iterations, and benchstat for statistical comparison of benchmark results.

✓ Live

Go Profiling — Performance Profiling with pprof and Trace for CPU, Memory, and Goroutines

Go pprof profiles CPU, memory, goroutine, and block contention with runtime/pprof and net/http/pprof for production profiling.

✓ Live

Go Modules — Dependency Management with go mod and Module Versioning

Go modules manage dependencies with go.mod and go.sum files, semantic versioning, and version selection for reproducible builds.

✓ Live

Go Dependency Management — Managing Dependencies with go mod and Vendoring Strategies

Go dependency management uses go mod for version control, replace directives for local overrides, and vendor directories for reproducible builds.

✓ Live

Go CLI Applications — Building Command-Line Tools with flag, cobra, and os/exec

Go CLI applications use flag package for simple args, cobra for complex commands, and os/exec for running external processes.

✓ Live

Go Web Frameworks — Building Web Applications with Gin, Echo, and Fiber

Go web frameworks like Gin, Echo, and Fiber provide routing, middleware, and context utilities for building high-performance web applications.

✓ Live

Go Middleware — HTTP Middleware Patterns for Logging, Auth, Rate Limiting, and CORS

Go HTTP middleware chains functions that wrap http.Handler for cross-cutting concerns like logging, authentication, rate limiting, and CORS.

✓ Live

Go Testing HTTP Handlers — Testing HTTP Servers with httptest and Test Suites

Go httptest package provides NewRecorder for handler testing and NewServer for integration testing with real HTTP requests and responses.

✓ Live

Go Deployment — Deploying Go Applications with Docker, Multi-stage Builds, and CI/CD

Go deployment uses Docker multi-stage builds for small images, CI/CD pipelines with testing, and cloud platform deployment to AWS, GCP, and Fly.io.

✓ Live

Go Microservices — Building Microservices with Go, gRPC, and Message Queues

Go microservices use HTTP/gRPC for communication, message queues for async processing, and service discovery for distributed architecture.

✓ Live

Go Mini Projects — Build Real-World Go Applications from Scratch

Go mini projects build a REST API server, CLI task manager, URL shortener, and file server applying slices, goroutines, HTTP, and JSON skills.

✓ Live

Go Ecosystem — Community, Frameworks, Tools, and Best Practices

Go ecosystem includes Gin and Echo for web, GORM for databases, test frameworks, and community resources like Go by Example and Awesome Go.

✓ Live

Go Testing Advanced — Fuzzing, Mocking, and Integration Testing Patterns

Go advanced testing covers fuzzing with testing.F, mock generation with GoMock, golden files, and integration tests with testcontainers.

✓ Live

Go Application Deployment — Deploying Go Applications with Systemd, Docker, and Cloud Services

Go deployment strategies include systemd service management, Docker multi-stage builds, and cloud deployment to Fly.io, Railway, and AWS Lambda.

✓ Live

Go Web APIs — Building Production REST APIs with Go, Validation, and Documentation

Go web APIs use Gin/Echo for routing, go-playground/validator for validation, and swaggo/swag for OpenAPI documentation generation.

✓ Live

Go Advanced Topics — Reflection, CGo, Code Generation, and Tooling for Expert Go

Go advanced topics include code generation with go generate, build tags for conditional compilation, plugin system, and WASM compilation.

✓ Live

Go Generics Basics — Complete Guide

Learn Go generics with type parameters, allowing functions and data structures to operate on different types while maintaining compile-time type safety.

✓ Live

Go Error Wrapping and errors.Is

Learn Go error wrapping with fmt.Errorf and %w, and how errors.Is and errors.As traverse the error chain for reliable sentinel error detection in your code.

✓ Live

Go Mutex Deadlock — Complete Guide

Learn Go mutex deadlock patterns, how improper lock ordering causes goroutines to block indefinitely, and strategies like lock hierarchies to prevent them.

✓ Live

Go Channel Patterns — Complete Guide

Learn Go channel communication patterns including fan-in, fan-out, pipeline, and worker pools for coordinating concurrent goroutines without shared memory.

✓ Live

Go Select Multiplexing — Complete Guide

Learn Go select statements for multiplexing channel operations, enabling goroutines to wait on multiple channels and respond to the first available one.

✓ Live

Go Context Deadline — Complete Guide

Learn the Go context package for propagating deadlines, cancellations, and request-scoped values across API boundaries and inside goroutine tree structures.

✓ Live

Go Sync WaitGroup — Complete Guide

Learn Go sync.WaitGroup for waiting on a collection of goroutines to finish, a fundamental synchronization primitive for coordinating concurrent work.

✓ Live

All 57 topics in Go Tutorials are published.