Catalog / Go Programming Language Cheatsheet
Go Programming Language Cheatsheet
A comprehensive cheat sheet for the Go programming language, covering syntax, data types, control flow, concurrency, and more. Perfect for quick reference and learning.
Basics and Syntax
Hello, World!
The classic first program.
Explanation:
|
Variable Declaration
|
Explicitly declares a variable with optional type.
|
|
Declares and initializes a variable, inferring the type. Only usable inside functions.
|
Multiple Declarations |
Declare multiple variables at once.
|
Constants
Declaration |
Constants are declared like variables, but with the
|
Iota |
Used for creating enumerated constants.
|
Data Types
Basic Data Types
Integers: Floating-Point Numbers: Complex Numbers: Boolean: String: Example:
|
Composite Types
Arrays |
Fixed-size sequence of elements of the same type.
|
Slices |
Dynamically-sized sequence of elements of the same type. Built on top of arrays.
|
Maps |
Key-value pairs where keys are unique.
|
Pointers
Declaration |
A pointer holds the memory address of a value.
|
Dereferencing |
Accessing the value pointed to by the pointer.
|
Control Flow
Conditional Statements
|
Switch Statement
Basic Switch |
Evaluates a variable against a list of cases.
|
Fallthrough |
Forces execution to continue to the next case.
|
Looping Constructs
|
Functions and Packages
Function Definition
Basic Syntax |
|
Multiple Return Values |
|
Named Return Values |
|
Packages and Imports
Importing Packages |
|
Package Aliases |
|
Exported Names |
Identifiers that start with a capital letter are exported from the package.
|
Concurrency
Goroutines
Lightweight, concurrent functions.
|
Channels
Declaration |
Used for communication between goroutines.
|
Sending and Receiving |
|
Buffered Channels |
Channels with a capacity.
|
WaitGroup
Waits for a collection of goroutines to finish.
|