Go is a compiled programming language.
It can be found at http://www.golang.org
Example Commands:
> go version
go version go1.0.2
> go help
specific to a function
>godoc fmt Println
First Program
This is the example of very first program (i.e. Hello World)
package main
import "fmt"
// this is a comment
/* Multiple line
comments */
func main() {
fmt.Println("Hello World")
}
save it as main.go and run as follow
> go run main.go
Explanation of the First Program
package main
This is know as a “package declaration”. Every Go pro- gram must start with a package declaration.
import "fmt"
The import keyword is how we include code from other packages to use with our program.
The fmt package (shorthand for format) implements formatting for in- put and output.
func main() {
fmt.Println("Hello World")
}
All functions start with the keyword func followed by the name of the function (main in this case),
A list of zero or more “parameters” surrounded by parentheses,
An optional return type and
A “body” which is surrounded by curly braces. This function has no parameters, doesn't re- turn anything and has only one statement
fmt.Println("Hello World")
This statement is made of three components.
First we access another function inside of the fmt package called Println (that's the fmt.Println piece, Println means Print Line).