Go-Cheatsheet
๐ Hello World package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
} ๐ก Tip: Every Go program starts with package main and a main() function. ๐ฆ Variables & Constants package main
import "fmt"
func main() {
var name string = "Maxon"
age := 25 // short declaration
const pi = 3.14159
fmt.Println(name, age, pi)
} ๐ก Tip: Use := for short variable declarations. Constants use const . ๐ข Data Types var a int = 42
var b float64 = 3.14
var c string = "Gopher"
var d bool = true ๐ก Tip: Go is statically typed but infers types automatically when possible. ๐ Control Flow for i := 1; i <= 5; i++ {
if i%2 == 0 {
fmt.Println(i, "is Even")
} else {
fmt.Println(i, "is Odd")
}
}
switch day := 3; day {
case 1:
fmt.Println("Mon")
case 2:
fmt.Println("Tue")
default:
fmt.Println("Other")
} ๐ก Tip: Go has no while — only for loops wi…