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+.

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