Go: Basic Tools
Note: Read the offical references to get the most updated information.
Basic Tools
Install
Follow the instructions in go.dev/doc/install
## example for amd64 1.20.5
$ wget https://go.dev/dl/go1.20.5.linux-amd64.tar.gz
$ $ rm -rf /usr/local/go && tar -C /usr/local -xzf go1.20.5.linux-amd64.tar.gz
## add to the rc file
$ export PATH=$PATH:/usr/local/go/bin
$ go version
Hello World
Rust files always end with the .go extension.
If you’re using more than one word in your filename, the convention is to use MixedCaps or mixedCaps.
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
Notes about the code:
-
funcis how we declare a function in Rust, the parentheses()indicate there are no parameter and the function body is wrapped in{}. -
mainis the name of a special funtion: it is always the first code that runs in every executable Go program, when you run the main package. - A package is a way to group functions, and it’s made up of all the files in the same directory.
- Import the
fmtpackage, to print to the console. This package is one of the standard library packages you got when you installed Go. - The line ends with a semicolon
;which indicates that this expression is over. - Use tabs for indentation and gofmt emits them by default. Use spaces only if you must.
Compile and run
$ go run .
Hello, World!
Leave a Comment