- Install
brew install go
- IDE
VScode: lightweight choice
go: you will install other dependencies
go snippets
- GoLand: standard choice
- Run
go run hello.go
// main.go
package main // required
import "fmt" // required
const text = "Hello Golang" // package-level var
func getText() string {
text := "hello Golang" // local to getText()
return text
}
func main() { // required
fmt.Println(text)
fmt.Println(getText())
}
go env // environment variables
go build // build to binary
go get // install packages
go version // version of go
- GOROOT: includes
cmd, standard lib and go compiler
- GOPATH: after 1.11, you don't have to worry about this 👇
- Before
1.11, you will always to change GOPATH to your current project folder.
- Now, you can use
go mod to map dependencies in GOPATH and don't need to change GOPATH anymore
export GO111MODULE=off # turn off module system
go mod init essential-go # init module
go list -m all # list dependencies
go mod tidy # remove unused
go get -u # update all