Basic Rules
- We use .go files
- Code Blocks in {}
- No styling freedom
- We do have semi-colon to separate sentences
- Case-sensitive
- Strongly typed
- NOT and object-oriented language
- No classes, no exceptions
- We have on file acting as the entry point with a main function
- A folder is a package
- Packages can have simple names or URLS(github.com/fem/my-library)
- Within one go file, we can have
- Variables
- Functions
- Type declarations
- Method declarations
Modules and CLI
- A module is a group of packages
- It’s our project
- It contains a go.mod file with configuration and metadata
- CLI manipulates the module
- go mod init
- go build
- go run
- go test
- go get
Create a GO module
go mod init shtb.dev/go/io
This will create a go.mod
file inside the folder with bellow contents
module shtb.dev/go/io
go 1.21.3
To run the module we run
go run .
It will scan the folder and look for a file main.go
and a function named main
Workspaces and CLI
-
A workspace is a new kind of multi-module app concept from 1.18
-
It contains a go.work file with configuration and metadata including whick module to use
-
CLI manipulates the workspace
go work init