Free Online Course · Self-paced

Golang Tutorial for Beginners (Hands-On)

Free, complete Go (Golang) tutorial in learning order: install, modules, syntax through structs, error handling, I/O and JSON, then goroutines, HTTP, databases, testing, security, logging, Docker/Lambda/cgo. 100+ runnable lessons on Go 1.21+.

  • 241 parts
  • ~1437 min total
  • Beginner to Advanced
  • Updated Jun 2026
Reviewed Deepak Prasad
Golang Tutorial for Beginners (Hands-On)
By Last updated

Go is the language that powers most modern cloud infrastructure - Docker, Kubernetes, Prometheus, Terraform, and most cloud-native control planes are written in it. This tutorial takes you from go install all the way to building production microservices, with examples tested on Go 1.21+.

Follow the chapters top to bottom for a single learning path: install and modules, variables through functions, error handling early, slices and maps, structs and interfaces, file I/O and JSON before concurrency, then goroutines and channels, networking and web frameworks, databases, testing and benchmarks, security, logging, and real-world deployment (Docker, Lambda, cgo). Every chapter is short and every snippet runnable.

The chapter list on this page is the full course index: every Go lesson is linked here. On other Go pages, the sidebar shows a shorter spine of core topics in learning order so navigation stays light; use this hub whenever you need the complete list—including task-specific how-tos, fixes, and interview prep.

Click Start the course with Install and Set Up, or jump to Concurrency - Goroutines, Channels, Sync or Networking, HTTP and Web Frameworks when you are ready. After this course, a natural next step is /kubernetes-operator-tutorial/ (writing operators in Go).

What you'll learn

  • Install Go, manage GOPATH/modules, and write your first program
  • Master syntax - variables, types, control flow, error returns, the comma-ok idiom
  • Build structs, methods, interfaces (and the famous "accept interfaces, return structs" pattern)
  • Use slices, maps, channels, and goroutines for concurrent, idiomatic Go
  • Build HTTP / gRPC / WebSocket servers and integrate with Postgres, Redis, MongoDB
  • Profile, benchmark, fuzz, and test Go code the right way

Prerequisites

  • Go 1.21+ installed
  • Comfortable on the command line
  • Familiarity with at least one other programming language

Syllabus

19 chapters · 241 lessons · ~1437 min of reading

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

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive …