annika-w
8/24/2017 - 10:38 AM

Go Basics

// Declaration
type Vertex struct {
	X, Y 	int
	Name 	string
}

// Definition
v0 := Vertex{}	// X, Y, Name are implicitly 0 and ""
v1 := Vertex{1, 2, "vert"}
v2 := Vertex{
	X: 1,
	Y: 2,
}

// Access
v1 := Vertex{1, 2, "vert"}
vertexX, vertexY := v1.X, v1.Y
vertexName := v1.name
// Declaration
var numbers0 [10]int    // Array
var numbers1 []int      // Slice

// Definition
primes := [6]int{2, 3, 5, 7, 11, 13}
var partOfPrimes []int = primes[1:4]