Comment


// Single line comment 

/*
Multiple 
line 
comment
*/
          

Variable


// Define variable
var stuff string 
// Initialize variable
stuff = "stuff"

// Alternate syntax, define and initialize variable on same line
var stuff string = "stuff"

// Declare multiple variables on one line
var stuff, things string = "stuff", "things"

// Types can be omitted and go will try to infer the type
var stuff = "stuff"

// Shortcut for declaring a variable, can only be used inside a function
stuff := "stuff"
          

Constant


const (
    stuff = "stuff"
    things = "things"
)
          

Pointer


var stuff string = "stuff"

// Define pointer with '*' and identify pointer target wth '&'
var other_stuff *string = &stuff

// Access pointer
*other_stuff
          

User Defined Types


type Stuff string

var stuff Stuff = "stuff"
          

Struct


// Kind of like classes in other languages
type StuffAndThings struct {
    stuff string
    things string
}

// Initialization
var myStuffAndThings = StuffAndThings{"stuff", "things"}

// Accessing attributes
myStuffAndThings.stuff
myStuffAndThings.things
          

Function


func Stuff(stuffandthings StuffAndThings) {
    fmt.Println(stuffandthings.stuff)
    fmt.Println(stuffandthings.things)
}

// Using a function
var s = StuffAndThings{"stuff", "things"}
Stuff(s)