go build: compiles a bung of go source code filesgo run: compiles and executes one or two filesgo fmt: formats all the code in each file in the current directorygo install: compiles and installs a packagego get: downloads the raw source code of someone else's packagego test: runs any tests associated with the current project
package main defines a package that can be compiled and the executed. Must have a func called 'main'
package calculator and package uploader defines a package that can be used as a dependency (helper code)
Give my package all the functionally inside "fmt"
bool: true - false
string: "Hi"
int: 0 - 999
float64: 10.0001var card string = "Ace of Spades"
card := "Ace of Spades"cards := []string{"Ace of Diamonds", "Other string"} for i, card := range cards {
fmt.Println(i, card)
}type deck []string
cards := deck{"Ace of Diamonds", newCard()}"Hi there!" -> String
[72 105 32 116 104 101 114 101 33] -> Byte slice
data []byte
asciitable.com[]byte("Hi there!")Example:
greeting := "Hi!"
fm.Println([]byte(greeting))func (d deck) print() {
for i, card := range d {
fmt.Println(i, card)
}
}Any variable of type deck now gets access to the print method.
For convention, we call the iterable with the first char of the name of the type.