## Features - Code not run on a VM (i.e. directly compiled to machine code). - Automatic garbage collection. ## Module - Collection of packages versioned together (e.g. a simple go repo on Github). - Defined by a `go.mod` file placed at its root directory. ## Package - Directory containing on or more `.go` source files. ## Commands ```temrinal $ go mod init github.com/h4k1m0u/repo # Initialize a new module in the current directory (ie. creates a new go.mod file) $ go run . # Compile and run the main go package $ go mod tidy # Install remote packages by scanning code for imports ``` ## Notions From [A Tour of Go](https://go.dev/tour): - Requirements for executables: a package named `main` and a function also named `main` (entry point of the program). - A name (fct or var) in a package is exported only if it begins with capital letter. - Types come after variable names. - A function can return any number of results. - It is possible to declare & initalize multiple variables on the same line. - Short variable declaration (:=) - To declare and initialize a variable: `s := "hello"` (valid only in a function). - Equivalent to: `var s string; s = "hello"` - Pointers: same principle as in C. - Variables without an initial value are zero-initialized. - Casting: `var i int = 42; var f float64 = float64(i)` - Constants declared with: `const world = "monde"` -