100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Go Cheat Sheet

Go Cheat Sheet

Go syntax, goroutines, channels, error handling, and package structure for writing concurrent, statically typed programs.

2 PagesIntermediateApr 5, 2026

Basic Syntax

Variables, control flow, and printing.

go
package mainimport "fmt"func main() {    age := 30              // short variable declaration    name := "Ada"    var pi float64 = 3.14159    if age >= 18 {        fmt.Println(name, "is an adult")    }    for i := 0; i < 5; i++ {        fmt.Println("Count:", i)    }}

Goroutines & Channels

Concurrency primitives built into the language.

go
func worker(id int, jobs <-chan int, results chan<- int) {    for j := range jobs {        results <- j * 2    }}func main() {    jobs := make(chan int, 5)    results := make(chan int, 5)    go worker(1, jobs, results)  // launch goroutine    for i := 1; i <= 5; i++ {        jobs <- i    }    close(jobs)    for i := 0; i < 5; i++ {        fmt.Println(<-results)    }}

Error Handling

Idiomatic multi-value error returns.

go
func divide(a, b float64) (float64, error) {    if b == 0 {        return 0, fmt.Errorf("cannot divide %f by zero", a)    }    return a / b, nil}func main() {    result, err := divide(10, 0)    if err != nil {        fmt.Println("Error:", err)        return    }    fmt.Println("Result:", result)}

Core Keywords

Common Go language keywords.

  • go- starts a new goroutine to run a function concurrently
  • chan- typed channel used to communicate between goroutines
  • defer- schedules a call to run when the surrounding function returns
  • interface{}/any- represents a value of any type
  • struct- composite type grouping named fields
  • select- waits on multiple channel operations
  • panic/recover- unwind the stack on fatal errors and optionally recover
  • :=- short variable declaration with type inference
Pro Tip

Use `go vet` and `-race` (go run -race ./...) during development to catch suspicious code and data races before they hit production.

Was this cheat sheet helpful?

Explore Topics

#Go#GoCheatSheet#Programming#Intermediate#BasicSyntax#GoroutinesChannels#ErrorHandling#CoreKeywords#Concurrency#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet