
Introducing Go: Build Reliable, Scalable Programs

Go is both the name of the programming language and the name for the toolset used to build and interact with Go programs.
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
Because creating a new variable with a starting value is so common, Go also supports a shorter statement: x := "Hello, World" Notice the : before the = and that no type was specified. The type is not necessary because the Go compiler is able to infer the type based on the literal value you assign the variable (because you are assigning a
... See moreCaleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
Go has two floating-point types: float32 and float64 (also often referred to as single precision and double precision, respectively). It also has two additional types for representing complex numbers (numbers with imaginary parts): complex64 and complex128. Generally, we should stick with float64 when working with floating-point numbers.
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
Functions start with the keyword func, followed by the function’s name. The parameters (inputs) of the function are defined like this: name type, name type, …. Our function has one parameter (the list of scores) that we named xs. After the parameters, we put the return type. Collectively, the parameters and the return type are known as the function
... See moreCaleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
time.After creates a channel, and after the given duration, will send the current time on it (we weren’t interested in the time, so we didn’t store it in a variable).
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
Other programming languages have a lot of different types of loops (while, do, until, foreach, …) but Go only has one that can be used in a variety of different ways.
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
In Go, we can create a TCP server using the net package’s Listen function. Listen takes a network type (in our case, tcp) and an address and port to bind, and returns a net.Listener: type Listener interface { // Accept waits for and returns the next connection to the listener. Accept() (c Conn, err error) // Close closes the listener. // Any blocke
... See moreCaleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
package main import "fmt" func main() { panic("PANIC") str := recover() // this will never happen fmt.Println(str) } But the call to recover will never happen in this case, because the call to panic immediately stops execution of the function. Instead, we have to pair it with defer: package main import "fmt" func main(
... See moreCaleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
Channels provide a way for two goroutines to communicate with each other and synchronize their execution.