
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
Using a channel like this synchronizes the two goroutines. When pinger attempts to send a message on the channel, it will wait until printer is ready to receive the message (this is known as blocking).
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
string is a sequence of characters with a definite length used to represent text. Go strings are made up of individual bytes, usually one for each character (characters from some languages, such as Chinese, are represented by more than one byte).
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
In Go, if something starts with a capital letter, that means other packages (and programs) are able to see it. If we had named the function average instead of Average, our main program would not have been able to see it.
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
Methods Although this is better than the first version of this code, we can improve it significantly by using a special type of function known as a method: func (c Circle) area() float64 { return math.Pi * c.r c.r } In between the keyword func and the name of the function, we’ve added a receiver. The receiver is like a parameter — it has a name and
... See moreCaleb 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
... See moreCaleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
copy takes two arguments: dst and src. All of the entries in src are copied into dst overwriting whatever is there. If the lengths of the two slices are not the same, the smaller of the two will be used.
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
The fmt package (shorthand for format) implements formatting for input and output.
Caleb Doxsey • Introducing Go: Build Reliable, Scalable Programs
RPC The net/rpc (remote procedure call) and net/rpc/jsonrpc packages provide an easy way to expose methods so they can be invoked over a network (rather than just in the program running them): package main import ( "fmt" "net" "net/rpc" ) type Server struct {} func (this *Server) Negate(i int64, reply *int64) error { *reply = -i return nil }
... See more