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
iotaand 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/elseStatementsswitchStatementsswitch truePattern (Conditional Cases)
- Basic
forLoops - Range Loops (
for range) - Simulate
whileLoops - Infinite Loops
breakandcontinue- Loop Labels
gotoStatement
- Common String Functions (
stringspackage) - String Formatting
- Type Conversion (String β Number) (
strconvpackage) - Regular Expressions (
regexp) - Iterating Over Bytes and Runes
- Byte Slice Manipulation (
bytespackage)
- Arrays and Fixed-Length Arrays
- Size Inference with
[...]T - Slices and Slice Literals
- Iteration with
range - Copying and Appending Slices
slicesPackage Functions (note: you should useslicesinstead ofsort)uniquePackage Functions
- Declare and Initialize Maps
- Map Literals
- Access and Modify Keys
- Iterate Over Maps
- Delete Keys from Map (
delete()function) - Comma-ok Idiom
mapsPackage Functions
- 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
- Return and Handle
errorValues - Must Idiom (Short-Circuit Failures)
- Use
panic,recover, anddefer - Define Custom Error Types
- Wrap Errors with
%wanderrors.New - Use
errors.Isanderrors.As
- 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
- Generic Function Syntax
- Define Generic Struct Types
- Type Constraints:
any,comparable,~T - Union Types and Type Sets
- Generics with Interfaces
- Type Aliases with Generics
cmpPackage Functions
- Goroutines (
goKeyword) - Channels (Buffered and Unbuffered, Comma-ok Idiom, Direction Types, Iteration)
selectStatementsync.WaitGroupfor Goroutine Synchronizationsync.Mutexfor Mutual ExclusioncontextPackage (Timeouts, Cancellation, Passing Values)
iopackage (Readers, Writers, Copying)- File Operations (
ospackage) - Stdin, Stdout
- HTTP Requests (
net/httppackage) bufiopackage (Buffered I/O, Scanner, Reader, Writer)
- JSON (
encoding/jsonpackage) and Encoder examples - XML (
encoding/xmlpackage) - CSV (
encoding/csvpackage)
io.Pipefor In-Memory StreamingsyncPackage- RWMutexes - Read/Write Locks
- Once
- Pool
- Cond
- Atomic Operations (
sync/atomicPackage)
- Deadlocks, Race Conditions (
-raceflag), and Goroutine Leaks - Concurrency Patterns
- Fan-out, Fan-in
- Generator
- Pipeline
- Worker Pool
- Semaphore
- Base64 (
encoding/base64package) - Base32 (
encoding/base32package) - Hexadecimal (
encoding/hexpackage)
- Gzip (
compress/gzippackage) - Zlib (
compress/zlibpackage) - Flate (
compress/flatepackage)
- Reflection & Schema Validation
- Testing, Benchmarking and
testify - HTTP Requests and HTTP Clients
- HTTP Server, HTMX, Logging, and Environment Variables
- Networking - TCP and UDP
- Websockets
- gRPC and Protobufs
- Databases - SQL, NoSQL, and ORM
- Built-in advanced data structures - Heap, Linked List, and Ring
- C and Assembly in Go