All Go source code must belong to a package. Declare a package in go using the following syntax…
package <name>
Go programs start in the main
package.
Example
package main
This serves as the entry point for an executable.
You can import either by mutliple import or factored import
Example
// Multiple import
import "fmt"
import "net/http"
import "time"
// Factored import
import (
"fmt",
"net/http",
"time",
)
Exported symbols allows the symbol to be used in other packages
Exported symbols is spelt via PascalCasing
Go convention for symbols is to use camelCasing
(unexported)
Go does not allow circular dependencies
Packages allow programs to split up source code to seperate files instead of keeping it all in package main
To create a Go package
go mod init <top-package-name>
Example
go mod init indigo
which should result in a go.mod
file in current working directory
There are 3 rules for structuring the project
package <name>
name must be the same name as the directory the file is currently in
Example
TODO!