Basic Cheatsheet

Variables

var msg string
var msg = "Hello, world!"
var msg string = "Hello, world!"
var x, y int
var x, y int = 1, 2
var x, msg = 1, "Hello, world!"
msg = "Hello"

var (
  x int
  y = 20
  z int = 30
  d, e = 40, "Hello"
  f, g string
)

Constants

const Phi = 1.618
const Size int64 = 1024
const x, y = 1, 2
const (
  Pi = 3.14
  E  = 2.718
)
const (
  Sunday = iota
  Monday
  Tuesday
  Wednesday
  Thursday
  Friday
  Saturday
)

Basic Types

Structs

Arrays

Slices

Maps

Loops

Ranges

Last updated

Was this helpful?