updated: 8th of February 2021
published: 19th of November 2019
There are a number of methods to define variables in Go.
// Initialise variable with its zero value
// explicitly defining the variables type
var stuff string
// Assign a value to "stuff" variable
stuff = "stuff"
// Initialise variable and assign a value
var stuff string = "stuff"
// Shortcut method to initialise variable and assign a value
// The type will be inferred from the value
// This method can only be used inside a function
stuff := "stuff"
// Declare multiple variables on a single line
var stuff, things string = "stuff", "things"
// Alternate method to declare multiple variables
var (
stuff = "stuff"
things = "things"
)
// Constants are variables were the value cannot be changed
const stuff string = "stuff"
https://gobyexample.com/variables
https://www.golang-book.com/books/intro/4
https://golangbot.com/variables/
https://learning.oreilly.com/library/view/learning-go/9781492077206/ch02.html