Go is an open source, compiled, garbage-collected, concurrent system programming language.
Go aims to provide the efficiency of a statically typed compiled language with the ease of programming of a dynamic language.
Other goals include:
Go's mascot is a gopher.
Visit the Go programmingdownload page and choose the option corresponding to your platform or operating system.
Go was designed at Google in 2009 by Robert Griesemer, Rob Pike, and Ken Thompson.
Let's start with a simple example, the venerable hello world program.
packagemainimport"fmt"funcmain(){fmt.Println("Hello, World!")}
As you can see there is a lot going on here. The first line:
packagemain
starts every go source file. It states which package this file belongs to. Think of a package as a bag of code, where you are going to stuff the internals of your programs into. Themain package is special, and will we get into that in a moment.
import"fmt"
The line declares all the packages (or bags of code others have written to help us do things — also known as libraries) we are going to use. In this case, we are going to use thefmt (the format package: pronounced fa-umpt) Again, in later sections, we will delve deeper into packages.
funcmain(){…}
Here we declare a function (```func```). A function is a set of instructions that we provide to the computer to get it to do what we want it to do. There are few special functions in go, and that function is the entry point of the program.