Golang
Introduction
Hello World
Execution
- It declares the
main
package, which is required for executable programs in Go. - It imports the
fmt
package, which provides formatting and printing functions. - The
main()
function is the entry point of the program. - Inside
main()
, it usesfmt.Println()
to print "Hello Gophers!" to the console.
Go CLI Commands
Compile and run code
Compile
Running compiled file
Test packages
Install packages/modules
List installed packages/modules
Update packages/modules
Format package sources
See package documentation
Add dependencies and install
See Go environment variables
See version
Go Modules
Go projects are called modules
. Each module has multiple packages
Each
package should has a scoped functionality. Packages talk to each other to
compose the code. A module needs at least one package, the main
. The package
main needs a entry function called main
.
Create Module
Tip
By convention, modules names has the follow structure:
domain.com/user/module/package
.
Example: github.com/spf13/cobra