Table of Contents
GoLang Docs - GoLang Tutorials
Learn to Code - for Free | Codecademy
Learn to become a Go developer
This is my summary of the Golang basics. There is always a block of code and below it some bullet-points describing what it does + notable things that might be unique to Golang. I go from general to more specific / complex here, therefore, it might be useful to read through everything top to bottom if you are completely new to Golang, like me.
// define a file to be executable
package main
// import packages
import "fmt"
// declare a function
func main () {
fmt.Println("Hello World!")
}
package mainline will automatically execute the main function at the end of the script. We do not have to call it explicitly.package main are considered libraries, accumulations of code and can be used in other programs themselves.// do multiple imports like his
import "fmt"
import "time"
// OR
import (
"fmt"
t "time" // the 't' will be the shorthand for the package
)
# run files without compiling
go run main.go
# compile go scirpts
go build main.go
# execute binary
./main
# search the go docs like this
go doc fmt
# search for specific function
go doc time.Now