
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
Channels provide a way for two goroutines to communicate with each other and synchronize their execution.
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
In addition to the indexing operator, Go includes two built-in functions to assist with slices: append and copy. append append adds elements onto the end of a slice. If there’s sufficient capacity in the underlying array, the element is placed after the last element and the length is incremented. However, if there is not sufficient capacity, a new
... See moreCaleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
Go also provides a shorter syntax for creating arrays: x := [5]float64{ 98, 93, 77, 82, 83 }
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
Because the length of an array is part of its type name, working with arrays can be a little cumbersome. Adding or removing elements as we did here requires also changing the length inside the brackets. Because of this and other limitations, you rarely see arrays used directly in Go code. Instead, you will usually use a slice, which is a type built
... 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
Like integers, floating-point numbers have a certain size (32 bit or 64 bit). Using a larger-sized floating-point number increases its precision
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
Go has a way of making these accidental similarities explicit through a type known as an interface. Here is an example of a Shape interface: type Shape interface { area() float64 } Like a struct, an interface is created using the type keyword, followed by a name and the keyword interface. But instead of defining fields, we define a method set. A me
... See moreCaleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
Go mostly doesn’t care about whitespace