GoLang_System_Essentials_Notes_Chapter_1

Why Go

Apart from easy to read code and simple learning curve which encourages everyone to quickly adopt the existing code system, Go has a very strong concurrency model.

Concurrency defines throughput of your system. When a task is waitnig for I/O resources, if you can code like other task can leverage the idle CPU, then throughput of your entire program will be increased.

Go uses channels for communicating between threads and go follows CSP when it comes to implementation of threads and thread communication.
There is an excellent paper written on same. https://www.cs.cmu.edu/~crary/819-f09/Hoare78.pdf

And another prinicple, share memory not by locks but by communicating. We can write a lot about go concurrency, but lets see in practicals.

Go in-built tools

go build main.go to generate go binary
go test to run tests
go run main/hello.go to run your program but no binary generation
go vet filename.go to check errors in your code.
go fmt file.go to format your go code.

Cross platform development

two main env variables, GOOS and GOARCH
GOOS for OS Target
GOARCH for CPU arch, amd64, darwin etc
Linux build command
GOOS=linux GOARCH=amd64 go build
For Mac
GOOS=darwin GOARCH=amd64 go run

We can also add build tags for specific platform

// go:build windows
package main
import "fmt"
func main() {
    fmt.Println("This is Windows!")
}
// go:build linux
package main
import "fmt"
func main() {
    fmt.Println("This is Linux!")
}
GOOS=windows go build -o app.exe
GOOS=linux go build -o app