infuerno.github.io

Pluralsight: The Go Programming Language, John Sonmez

Overview

References

Text Editors

Development setup

Variables, Types and Pointers

http://golang.org/ref/spec

Variables

Pointers

User Defined Types

// capital S means this type is publically visible
type Saluation struct { 
    name string 
    greeting string
} 

func main() {
        var x Salutation = Salutation {"bob", "hyas"} // OR
        var x = Salutation {"bob", "hyas"} // OR
        x := Salutation {"bob", "hyas"}
}

Constants

// here A would be equal to 0, B to 1 and C to 2
const (
    A = iota
    B = iota
    C = iota
    D // don't need to repeat after the first one
)

Functions

Variadic functions

Function types

Closures

A function which returns a function

func CreatePrintFunction(custom string) Printer {
    return func(m string) {
        fmt.Println(m + custom)
    }
}

This is a closure since the function which is returned has the custom variable hard coded in its definition, yet it can be changed each time the outer function itself is called

Examples of function usage (advanced): https://golang.org/doc/codewalk/functions/

Branching

Loops

http://golang.org/doc/effective_go.html#for http://golang.org/ref/spec#For_statements

Maps

myMap := map[string]string {
    "Bob": "Mr",
    "Jane": "Mrs",
}

Arrays

Slices

Methods

Interfaces

Concurrency