Go (Golang) Basics Cheatsheet
Quick reference for Go syntax, types, functions, structs, methods, concurrency, and utilities.
| Item | Description | Example | Category |
|---|---|---|---|
| package | Define package | package main | Syntax |
| import | Import packages | import "fmt" | Syntax |
| func main() | Program entry point | func main() { fmt.Println("Hello, Go") } | Syntax |
| var | Declare variable | var x int = 10 | Types |
| := | Short variable declaration | x := 10 | Types |
| const | Define constant | const pi = 3.14 | Types |
| int, float64, string, bool | Basic types | var name string = "Go" | Types |
| array, slice, map | Collections | nums := []int{1,2,3} | Types |
| func | Define function | func add(a int, b int) int { return a+b } | Functions |
| defer | Execute at function exit | defer fmt.Println("Done") | Functions |
| return | Return value | return x + y | Functions |
| struct | Define struct | type Person struct { Name string; Age int } | Structs |
| new | Create new struct | p := new(Person) | Structs |
| p := Person{} | Struct literal | p := Person{Name: "John", Age: 30} | Structs |
| func (p Person) Method() | Define method on struct | func (p Person) Greet() { fmt.Println("Hello", p.Name) } | Methods |
| go | Start goroutine | go doSomething() | Concurrency |
| channel | Communication between goroutines | ch := make(chan int) | Concurrency |
| <-ch | Receive from channel | value := <-ch | Concurrency |
| ch <- value | Send to channel | ch <- 10 | Concurrency |
| fmt.Println | Print to console | fmt.Println("Hello") | Utilities |
| len() | Get length of string, slice, map | len(nums) | Utilities |
| make() | Create slice, map, channel | s := make([]int, 10) | Utilities |