GO
Go Cheatsheet
Core Go syntax - types, goroutines/channels, and the error-handling pattern used throughout idiomatic Go code.
Basics
var x int = 5Typed variable declaration
x := 5Short variable declaration with inference
func add(a, b int) int { return a + b }Function declaration
type Point struct { X, Y int }Struct declaration
slice := []int{1, 2, 3}Slice literal
Error handling
val, err := doSomething()Idiomatic multi-return with error
if err != nil { return err }Standard error check
errors.New("message")Create a simple error
fmt.Errorf("failed: %w", err)Wrap an error with context
Concurrency
go doSomething()Start a goroutine
ch := make(chan int)Create a channel
ch <- valueSend a value on a channel
val := <-chReceive a value from a channel
var wg sync.WaitGroupWait for goroutines to finish