Free Online Course · Self-paced · Hands-on

Golang Tutorial for Beginners (Hands-On)

Free Golang tutorial for beginners: 200+ runnable lessons on modules, structs, errors, goroutines, HTTP and gRPC APIs, databases, testing, and Docker.

  • 19 chapters
  • 242 lessons
  • ~22h
  • Beginner to Intermediate
  • Tested with Go 1.27.x
  • Updated Sep 2026
Golang Tutorial for Beginners (Hands-On)
By Last updated

About this course

This is a free, self-paced Go course that starts with installing the toolchain and ends with HTTP and gRPC services packaged in Docker images. Docker, Kubernetes, Prometheus, and Terraform are all written in Go, and the syllabus is aimed at that kind of work: services, command-line tools, and the glue code around them. Lessons refreshed this year run on Go 1.27, the current release listed on go.dev.

The order is deliberate. Go returns errors as ordinary values, so error handling comes straight after functions, and file I/O and JSON come before goroutines. When you reach concurrency you already know how a Go program reports failure, which makes a leaked goroutine or an ignored error much easier to trace. Every lesson is a short program you can run with go run on your own machine.

If Go is your first compiled language, work through the chapters in order. If you already write Go, jump straight to goroutines and channels, the networking and web framework chapter, or testing and benchmarks. The CLI lessons are a good standalone path too, moving from raw arguments to flag and then Cobra.

What you'll learn

  • Install Go, create a module with go mod init, and import local, remote, and private packages
  • Write idiomatic Go with typed variables, strings, control flow, functions, closures, and pointers
  • Return errors as values, use the comma-ok idiom, and know when panic and recover are the right tool
  • Model data with slices, maps, structs, methods, interfaces, embedding, and generics
  • Read and write files, parse JSON and YAML, and build command-line tools with flag and Cobra
  • Run concurrent work with goroutines, channels, WaitGroup, mutexes, and context cancellation
  • Build HTTP, gRPC, and WebSocket services backed by PostgreSQL, Redis, or MongoDB
  • Test, benchmark, fuzz, and lint Go code, then ship it in a small Docker image

Who this course is for

  • Developers who already write Python, Java, or JavaScript and want a compiled language for backend services
  • SREs and platform engineers who read Docker, Kubernetes, or Terraform source and want to write tools in the same language
  • Engineers building command-line tools that ship as one binary with no runtime to install on the target host
  • Anyone preparing for a Go developer interview who needs concurrency and error handling to feel routine

Prerequisites

  • Programming experience in at least one other language, including functions, loops, and basic data structures
  • A Linux, macOS, or Windows machine where you can install Go 1.24 or newer; the first chapter covers the install
  • Comfortable at the command line, including running commands, setting environment variables, and editing files
  • Docker, PostgreSQL, Redis, MongoDB, or an AWS account only for the chapters that use them; the core syllabus needs none of these

Versions and testing environment

Every command in this course was run on this stack

ComponentVersionNotes
Go 1.27.x Lessons refreshed in 2026 were run with Go 1.27.0 on RHEL 10.2
Go 1.24.x Most other lessons were run with Go 1.24 on 64-bit Linux; the Go 1 compatibility promise keeps that code building on newer releases
Operating system RHEL 10.2, Linux kernel 6.14 Commands assume a POSIX shell; Windows installation has its own lesson
Datastores and drivers Redis 7.x, go-redis v9, mongo-driver v2.6.x The Redis examples need a running redis-server; the MongoDB examples were compile-checked and need Atlas or a local instance to run

Syllabus

19 chapters · 242 lessons · ~22h of reading

  1. 1 Install and Set Up 9 lessons · ~1h 7m
    1. Part 1 Install Go 1.21+ on Ubuntu 8 min read
    2. Part 2 Install Go on Windows 4 min read
    3. Part 3 Uninstall Go 11 min read
    4. Part 4 Upgrade your Go version 5 min read
    5. Part 5 Best IDE for Go 13 min read
    6. Part 6 Getting started with Go 12 min read
    7. Part 7 Hello World in Go 4 min read
    8. Part 8 GOPATH vs GOROOT 5 min read
    9. Part 9 Set the GOPATH variable 5 min read
  2. 2 Modules and Packages 13 lessons · ~1h 30m
    1. Part 10 Create a custom Go module 6 min read
    2. Part 11 Package layout and conventions 5 min read
    3. Part 12 Call a function from another package 8 min read
    4. Part 13 Import a local package 4 min read
    5. Part 14 Import a local package without GOPATH 8 min read
    6. Part 15 Import a struct from another file 7 min read
    7. Part 16 Import private repositories 5 min read
    8. Part 17 go get a specific version 5 min read
    9. Part 18 Remove an installed package 10 min read
    10. Part 19 List installed packages 5 min read
    11. Part 20 Underscore (_) in front of imports 9 min read
    12. Part 21 Fix: cannot find package even if GOPATH is set 9 min read
    13. Part 22 Fix: go.mod file not found 9 min read
  3. 3 Variables, Constants, Types 14 lessons · ~1h 15m
    1. Part 23 Global variables 6 min read
    2. Part 24 Variable scope 8 min read
    3. Part 25 Variable naming conventions 12 min read
    4. Part 26 Fix: declared and not used 6 min read
    5. Part 27 Integer types (int, int32, int64, uint) 5 min read
    6. Part 28 Convert int to int64 5 min read
    7. Part 29 Convert byte to int 6 min read
    8. Part 30 Convert float64 to int 6 min read
    9. Part 31 Type casting Coming soon
    10. Part 32 Convert bool to string 3 min read
    11. Part 33 Cast to string 3 min read
    12. Part 34 Array constants 5 min read
    13. Part 35 Declare constant maps 5 min read
    14. Part 36 What does & (ampersand) mean in Go? 5 min read
  4. 4 Strings 18 lessons · ~1h 34m
    1. Part 37 String.Contains() 6 min read
    2. Part 38 Compare strings 5 min read
    3. Part 39 Split a string 8 min read
    4. Part 40 Split and assign to variables 4 min read
    5. Part 41 String interpolation 7 min read
    6. Part 42 Multi-line strings 3 min read
    7. Part 43 Trim whitespace 7 min read
    8. Part 44 Trim leading and trailing spaces 3 min read
    9. Part 45 Padding and formatting 4 min read
    10. Part 46 Escape backslash in strings 4 min read
    11. Part 47 Remove backslash from string 4 min read
    12. Part 48 Tab characters in strings 5 min read
    13. Part 49 Convert string to uint8 7 min read
    14. Part 50 Convert bytes to string 3 min read
    15. Part 51 Test if a string is empty 6 min read
    16. Part 52 Base64 encode/decode 4 min read
    17. Part 53 strconv package 8 min read
    18. Part 54 URL encode/decode 6 min read
  5. 5 Control Flow 8 lessons · ~51 min
    1. Part 55 if / else 7 min read
    2. Part 56 Ternary equivalents in Go Coming soon
    3. Part 57 switch statement 10 min read
    4. Part 58 for loop (the only loop) 12 min read
    5. Part 59 while-loop pattern 10 min read
    6. Part 60 break and continue 4 min read
    7. Part 61 Iterate over an array 4 min read
    8. Part 62 Iterate over a slice in reverse 4 min read
  6. 6 Functions 14 lessons · ~1h 28m
    1. Part 63 Functions in Go 12 min read
    2. Part 64 Default parameter values 3 min read
    3. Part 65 Optional parameters 7 min read
    4. Part 66 Variadic functions 7 min read
    5. Part 67 Functions as parameters 8 min read
    6. Part 68 Functions that accept multiple types 5 min read
    7. Part 69 Function vs method 4 min read
    8. Part 70 Closures 7 min read
    9. Part 71 Anonymous functions 7 min read
    10. Part 72 Return multiple values 4 min read
    11. Part 73 defer keyword 4 min read
    12. Part 74 Pass by reference vs value 4 min read
    13. Part 75 Go pointers tutorial 10 min read
    14. Part 76 init() function and execution order 6 min read
  7. 7 Error Handling 6 lessons · ~27 min
    1. Part 77 Return an error 5 min read
    2. Part 78 Create a new error 4 min read
    3. Part 79 The comma-ok idiom 4 min read
    4. Part 80 panic and recover 4 min read
    5. Part 81 defer and os.Exit gotcha 5 min read
    6. Part 82 Detect nil 5 min read
  8. 8 Arrays, Slices and Maps 19 lessons · ~1h 36m
    1. Part 83 Arrays and structs overview 4 min read
    2. Part 84 Pass an array to a function 4 min read
    3. Part 85 Pass a slice to a function 4 min read
    4. Part 86 Append to a slice 4 min read
    5. Part 87 Append and return a slice 4 min read
    6. Part 88 Concatenate slices uniquely 5 min read
    7. Part 89 Remove from a slice 4 min read
    8. Part 90 Delete elements from a slice 5 min read
    9. Part 91 Remove duplicates from a slice 3 min read
    10. Part 92 Search for an element in a slice 16 min read
    11. Part 93 Check if an array contains a value 5 min read
    12. Part 94 Merge slices 4 min read
    13. Part 95 Sort slices and arrays (Ints, Slice, stable, descending) 5 min read
    14. Part 96 Maps in Go 5 min read
    15. Part 97 Check if a key exists in a map 12 min read
    16. Part 98 Length of a map 3 min read
    17. Part 99 Delete from a map 2 min read
    18. Part 100 Copy a map 4 min read
    19. Part 101 Convert a slice into a map 3 min read
  9. 9 Structs and Interfaces 20 lessons · ~1h 54m
    1. Part 102 Structs in Go 7 min read
    2. Part 103 Anonymous structs 8 min read
    3. Part 104 Constants in structs 3 min read
    4. Part 105 Print a struct 4 min read
    5. Part 106 Copy a struct 3 min read
    6. Part 107 Compare structs, slices, and maps 7 min read
    7. Part 108 Check if a struct is empty 4 min read
    8. Part 109 Set default values in structs 3 min read
    9. Part 110 Remove fields from a struct 5 min read
    10. Part 111 Store values in a struct in a loop 3 min read
    11. Part 112 Methods on a type 5 min read
    12. Part 113 Constructor pattern 6 min read
    13. Part 114 Interfaces and interface-to-string 13 min read
    14. Part 115 Type assertion 9 min read
    15. Part 116 Struct embedding 9 min read
    16. Part 117 Generics (Go 1.18+) 7 min read
    17. Part 118 Enum pattern in Go 2 min read
    18. Part 119 Tuple-like patterns 4 min read
    19. Part 120 reflect package 8 min read
    20. Part 121 Print the type of a value 4 min read
  10. 10 File I/O and OS 25 lessons · ~2h 49m
    1. Part 122 os package overview 10 min read
    2. Part 123 Environment variables (read and set) 6 min read
    3. Part 124 Read a file - all methods 7 min read
    4. Part 125 Read a file into a variable 4 min read
    5. Part 126 Append to a file 8 min read
    6. Part 127 Read and update the same file 6 min read
    7. Part 128 Seek in a file 4 min read
    8. Part 129 Read a file with a timeout 9 min read
    9. Part 130 Copy a file (preserve permissions) 3 min read
    10. Part 131 os.Stat() examples 6 min read
    11. Part 132 Create nested directories 3 min read
    12. Part 133 Get the current directory 4 min read
    13. Part 134 Watch a directory (fsnotify) 8 min read
    14. Part 135 Execute shell commands 15 min read
    15. Part 136 Read command-line arguments 7 min read
    16. Part 137 flag package examples 6 min read
    17. Part 138 Parse multiple inputs 3 min read
    18. Part 139 Hide password input 5 min read
    19. Part 140 Build a CLI prompt 5 min read
    20. Part 141 Interactive CLI with go-prompt 5 min read
    21. Part 142 Build CLIs with Cobra 8 min read
    22. Part 143 Configuration with Viper 15 min read
    23. Part 144 Kill a process 9 min read
    24. Part 145 Monitor a background process 5 min read
    25. Part 146 Capture Ctrl+C signals 8 min read
  11. 11 JSON, YAML and Time 14 lessons · ~1h 42m
    1. Part 147 Parse JSON (string, file, API) 10 min read
    2. Part 148 json.Unmarshal() 14 min read
    3. Part 149 omitempty in JSON tags 8 min read
    4. Part 150 Convert a map to JSON 4 min read
    5. Part 151 Convert a map to a struct 6 min read
    6. Part 152 Parse a YAML file 9 min read
    7. Part 153 time package basics, duration, and measuring elapsed time 11 min read
    8. Part 154 Format time 8 min read
    9. Part 155 Get current time in milliseconds 3 min read
    10. Part 156 Multiply a duration by an integer 3 min read
    11. Part 157 Subtract a duration from a time 9 min read
    12. Part 158 Zero value for time.Time 3 min read
    13. Part 159 time.Ticker and ticker loops 8 min read
    14. Part 160 Run repetitive tasks at intervals 6 min read
  12. 12 Concurrency - Goroutines, Channels, Sync 13 lessons · ~1h 39m
    1. Part 161 Goroutines explained 5 min read
    2. Part 162 Return a value from a goroutine 4 min read
    3. Part 163 Goroutines vs OS threads 10 min read
    4. Part 164 Channels in Go 10 min read
    5. Part 165 Buffered channels 6 min read
    6. Part 166 Channels with multiple receivers 9 min read
    7. Part 167 Check if a channel buffer is full 5 min read
    8. Part 168 Stop a goroutine cleanly 9 min read
    9. Part 169 Mutex 5 min read
    10. Part 170 WaitGroup 8 min read
    11. Part 171 Concurrency patterns overview 12 min read
    12. Part 172 Fan-out / fan-in pattern 12 min read
    13. Part 173 context package 4 min read
  13. 13 Networking, HTTP and Web Frameworks 21 lessons · ~2h 41m
    1. Part 174 Build a Go web server 14 min read
    2. Part 175 net/http package 5 min read
    3. Part 176 HTTP client with timeout 6 min read
    4. Part 177 POST a JSON request 4 min read
    5. Part 178 Set HTTP cookies 5 min read
    6. Part 179 HTTPS request with a bad certificate 5 min read
    7. Part 180 Pass multiple strings into a URL 3 min read
    8. Part 181 Get the IP address 4 min read
    9. Part 182 TCP server and client 6 min read
    10. Part 183 UDP server and client 5 min read
    11. Part 184 WebSocket server 9 min read
    12. Part 185 Port ping utility 9 min read
    13. Part 186 Pick a Go web framework 9 min read
    14. Part 187 Build APIs with Gin 10 min read
    15. Part 188 Build APIs with Fiber 12 min read
    16. Part 189 Build APIs with Chi 17 min read
    17. Part 190 Build APIs with Gorilla Mux 3 min read
    18. Part 191 GraphQL in Go 6 min read
    19. Part 192 gRPC in Go 5 min read
    20. Part 193 JWT authentication 10 min read
    21. Part 194 JWT examples 14 min read
  14. 14 Databases and Storage 11 lessons · ~1h 31m
    1. Part 195 database/sql package 10 min read
    2. Part 196 SQLite3 in Go 9 min read
    3. Part 197 CRUD REST API with Postgres 9 min read
    4. Part 198 gRPC CRUD API with Postgres 15 min read
    5. Part 199 Get started with Redis in Go 3 min read
    6. Part 200 CRUD REST API with Redis 10 min read
    7. Part 201 MongoDB in Go 6 min read
    8. Part 202 In-memory DB with memdb 6 min read
    9. Part 203 FlashDB in Go 5 min read
    10. Part 204 AWS DynamoDB in Go 11 min read
    11. Part 205 Connection pool patterns 7 min read
  15. 15 Testing, Benchmarks, and Performance 7 lessons · ~45 min
    1. Part 206 Write tests in Go 8 min read
    2. Part 207 Benchmark Go code 8 min read
    3. Part 208 Fuzz testing in Go Coming soon
    4. Part 209 Performance tuning in Go 6 min read
    5. Part 210 Garbage collector explained 15 min read
    6. Part 211 golangci-lint 4 min read
    7. Part 212 Set CPU affinity 4 min read
  16. 16 Cryptography and Security 5 lessons · ~30 min
    1. Part 213 Encrypt and decrypt data 3 min read
    2. Part 214 SHA-256 hashing 8 min read
    3. Part 215 SHA-512 hashing 9 min read
    4. Part 216 Generate random strings 7 min read
    5. Part 217 Generate random booleans 3 min read
  17. 17 Logging and Observability 5 lessons · ~27 min
    1. Part 218 Log to a file 4 min read
    2. Part 219 logrus structured logging 5 min read
    3. Part 220 zap structured logging 7 min read
    4. Part 221 Change the default log format 5 min read
    5. Part 222 Print function name and line number in logrus 6 min read
  18. 18 Real-World Projects and Architecture 10 lessons · ~1h 29m
    1. Part 223 Hexagonal (ports & adapters) architecture in Go 13 min read
    2. Part 224 Build a Go microservice with Docker 12 min read
    3. Part 225 Docker multi-stage build for Go 3 min read
    4. Part 226 Deploy Go to AWS Lambda 12 min read
    5. Part 227 cgo tutorial 9 min read
    6. Part 228 Create a PAM module in Go 18 min read
    7. Part 229 GUI apps with Shiny 8 min read
    8. Part 230 FIFO queue implementation 4 min read
    9. Part 231 Queue implementation 5 min read
    10. Part 232 sed/awk equivalents in Go 5 min read
  19. 19 Math and Misc 10 lessons · ~1h 5m
    1. Part 233 math package overview 4 min read
    2. Part 234 math.Pow() 4 min read
    3. Part 235 regexp package 9 min read
    4. Part 236 io.Reader to string 5 min read
    5. Part 237 Convert []byte to io.Reader 5 min read
    6. Part 238 io.ReadCloser 5 min read
    7. Part 239 HTML body to string 9 min read
    8. Part 240 The Go gopher mascot story 6 min read
    9. Part 241 Go vs Rust 7 min read
    10. Part 242 Go interview questions 11 min read

Hands-on labs

6 guided builds you run yourself

  1. Build a CLI with subcommands and flags

    Scaffold a Cobra application with nested subcommands, local and persistent flags, and a --version flag you can test with go run.

  2. Run a WebSocket server and client

    Exchange text and JSON messages between a Go server and client with Gorilla WebSocket, then close the connection cleanly.

  3. Build a CRUD REST API on PostgreSQL

    Wire create, read, update, and delete endpoints to a PostgreSQL table and exercise each one over HTTP.

  4. Serve the same CRUD operations over gRPC

    Define the service in a .proto file, generate the Go code with protoc, and back each RPC with PostgreSQL.

  5. Package a Go service in a small Docker image

    Compile inside a golang image, then copy only the static binary into a minimal runtime image for deployment.

  6. Deploy a Go function to AWS Lambda

    Write a Go handler and deploy it to AWS Lambda with the Serverless Framework.

Where to go after this course

  • Official Go documentationThe language specification, Effective Go, and per-release notes, maintained by the Go team.
  • Kubernetes courseLearn the platform most Go services end up running on.
  • Kubernetes Operator courseOperators are written in Go, so this is where the concurrency and API chapters get used on real infrastructure.
  • Go interview questionsCheck your understanding of interfaces, goroutines, and error handling before a technical interview.

Frequently Asked Questions

Is Go the same as Golang?

Yes. The language is officially called Go. "Golang" comes from the project's original golang.org domain and stuck because "go" on its own is hard to search for. The website now lives at go.dev, but you will see both names used for the same language in docs, job ads, and package names.

Which Go version should I install?

Install the latest stable release from go.dev/dl. The Go team supports each major release until two newer ones are out, so right now Go 1.27 and 1.26 receive security fixes. Code written for an older Go 1.x release keeps compiling on newer ones under the Go 1 compatibility promise. Since Go 1.21, the go line in go.mod can also make the go command download a newer toolchain when a module needs one. Check the release history for the current supported pair.

Is Go harder to learn than Python?

The language itself is smaller than Python. It has one loop keyword, no classes or inheritance, and few ways to write the same thing. The extra effort goes into static types, pointers, and checking every returned error. In exchange, the compiler catches many mistakes before the program runs, and the result is a single binary you can copy to a server without installing a runtime.

Does Go run on Windows and macOS?

Yes. go.dev publishes installers for Windows, macOS, and Linux. The commands in this course were run on Linux, and Windows installation has its own lesson. You can also build for another platform from the machine you are on by setting two environment variables:

bash
GOOS=windows GOARCH=amd64 go build -o app.exe .

Should I learn Go or Rust?

Pick Go if you want to be productive on network services and tooling quickly. It has a garbage collector, fast compile times, and a large standard library for HTTP, JSON, and cryptography. Rust gives you memory safety without a garbage collector through its ownership rules, which suits systems code where every allocation matters, but it takes longer to learn. The Go vs Rust lesson compares them side by side.

Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with 15+ years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.

  • Go (programming language)
  • Python (programming language)
  • DevOps
  • Computer Security
  • Cloud Computing
  • Kubernetes
  • Linux
  • Ansible (software)