Practical Go programming guide covering the basics and some advanced topics. This guide is designed to help you quickly get started with Go and understand its core concepts.
- Print "Hello World!"
- Declare and Initialize Variables
- Data Types
- Constants
- Printing Variables
iota
and Enumerated Constants
- Declare Functions
- Function Parameters and Return Values
- Naked Returns
- Use Functions Across Files (Same Package)
- Arithmetic Operators
- Comparison Operators
- Logical Operators
- Bitwise Operators
- Assignment Operators
- Increment/Decrement Operators
if
/else
Statementsswitch
Statementsswitch true
Pattern (Conditional Cases)
- Basic
for
Loops - Range Loops (
for range
) - Simulate
while
Loops - Infinite Loops
break
andcontinue
- Loop Labels
goto
Statement
- Common String Functions (
strings
package) - String Formatting
- Type Conversion (String โ Number) (
strconv
package) - Regular Expressions (
regexp
) - Iterating Over Bytes and Runes
- Byte Slice Manipulation (
bytes
package)
- Arrays and Fixed-Length Arrays
- Size Inference with
[...]T
- Slices and Slice Literals
- Iteration with
range
- Copying and Appending Slices
- Declare and Initialize Maps
- Map Literals
- Access and Modify Keys
- Iterate Over Maps
- Delete Keys from Map (
delete()
function) - Comma-ok Idiom
- Function Values (First-Class Functions)
- Assign Functions to Variables
- Pass Functions as Parameters
- Return Functions from Functions
- Anonymous Functions
- Closures
- Variadic Functions (
...T
) - Recursive Functions
- Declare and Use Pointers (
*T
) - Get the Address of a Variable (
&
) - Dereference a Pointer (
*p
) - Modify Values Through Pointers
- Handle Nil Pointers Safely
- Allocate Memory with
new()
- Declare Struct Types
- Access and Modify Struct Fields
- Use Pointers to Structs
- Anonymous Structs
- Nested Structs
- Struct Methods with Receivers
- Declare Interfaces
- Implicit Interface Implementation
- Empty Interface (
interface{}
) - Type Assertions, Type Switches, and Comma-ok Idiom
- Type Aliases
- Built-in Interfaces:
error
,Stringer
, etc. - "Explicit" Interface Implementation
- Create Custom Packages
- Import Packages
- Package Visibility and Capitalization Rules
init()
Function
- Return and Handle
error
Values - Must Idiom (Short-Circuit Failures)
- Use
panic
,recover
, anddefer
- Define Custom Error Types
- Wrap Errors with
%w
anderrors.New
- Use
errors.Is
anderrors.As
- Generic Function Syntax
- Define Generic Struct Types
- Type Constraints:
any
,comparable
,~T
- Union Types and Type Sets
- Generics with Interfaces
- Type Aliases with Generics
io
package (Readers, Writers, Copying)- File Operations (
os
package) - Stdin, Stdout
- HTTP Requests (
net/http
package) bufio
package (Buffered I/O, Scanner, Reader, Writer)
- Goroutines (
go
Keyword) - Channels (Buffered and Unbuffered, Comma-ok Idiom, Direction Types, Iteration)
select
Statementsync
Package- WaitGroups
- Mutual Exclusion (Mutexes, RWMutexes - Read/Write Locks)
- Once
- Pool
- Cond
- Atomic Operations (
sync/atomic
Package)
context
Package (Timeouts, Cancellation, Passing Values)- Deadlocks, Race Conditions (
-race
flag), and Goroutine Leaks - Concurrency Patterns
- Fan-out, Fan-in
- Generator
- Pipeline
- Worker Pool
- Semaphore
- JSON
- XML
- HTTP Client Requests
- HTTP Server
- TCP
- UDP
- Websockets
- Testing & Benchmarking &
testify
& httptest - gRPC
- HTMX
- SLog
- Environment Variables
- Reflection
- Cryptography & Hashing & Compression
- C
- Assembly
slices
andmaps
Packagessort
Packageunique
Package- DBs (SQL, NoSQL) & ORM
flag
Packageunsafe
Package