Go-The-Complete-Developers-Guide
Go Command line tools
1. go build - compiles a bunch of go source code files
go build
go build main.go
2. go run - Compiles and executes one or two files
go run
go run main.go
3. go fmt - Formats all the code in each file in the current directory
go fmt
|| go fmt
go fmt main.go
4. go installs - Compiles and "installs" a package
go install
|| go fmt
go install main.go
5. go get - Downloads the source code of someone else's package
go get
6. go test - Run any tests associated with the current project
go test
Packages in Go
1. Executable Package:
package main
Defines a package that can be compiled and then executed
Must have a func called 'main'
2. Reusable Package:
package
Defines a package that can be used as a dependency(helper code)
Variables/Types in Go
Variable declaration
var
=
var card string = "Ace of spades"
Type can be omitted in Go. GO compiler will infer type based on the value.
var card = "Ace of spades"
Basic types in Go
| Type | Values |
| ------- | -------------- |
| bool | true, false |
| string | "hi", "hello" |
| int | 0, -1000, 9999 |
| float64 | 10.1, 0.0009, -100.003|