
Introducing Go: Build Reliable, Scalable Programs

Go is a statically typed programming language. This means that variables always have a specific type and that type cannot change.
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
Go also has another shorthand when you need to define multiple variables: var ( a = 5 b = 10 c = 15 )
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
Return types can have names We can name the return type like this: func f2() (r int) { r = 1 return }
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
Channels provide a way for two goroutines to communicate with each other and synchronize their execution.
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
Go has rich support for concurrency using goroutines and channels.
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
One thing to remember is that arguments are always copied in Go. If we attempted to modify one of the fields inside of the circleArea function, it would not modify the original variable. Because of this, we would typically write the function using a pointer to the Circle: func circleArea(c Circle) float64 { return math.Pi * c.r c.r }
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
Multiple values can be returned Go is also capable of returning multiple values from a function. Here is an example function that returns two integers: func f() (int, int) { return 5, 6 } func main() { x, y := f() }
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
The first line says this: package main This is known as a package declaration, and every Go program must start with it. Packages are Go’s way of organizing and reusing code. There are two types of Go programs: executables and libraries. Executable applications are the kinds of programs that we can run directly from the terminal (on Windows, they en
... See moreCaleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
The fmt package (shorthand for format) implements formatting for input and output.