Environment Variables

GOPATH vs GOROOT

GOPATH Subdirectories

  1. ~/go/src/ - source code location
  2. ~/go/pkg/ - shared libraries location
  3. ~/go/bin/ - compiled code location

image (1).png

Package Management

History of Go Modules

A module has many projects. Modules are isolated workspaces, decoupled from the . This is useful if many code-bases exist on different systems.

A module has many projects. Modules are isolated workspaces, decoupled from the gopath. This is useful if many code-bases exist on different systems.

Creating a Module

Initializing a Folder as a Module

  1. Go to inside the folder where you want the module to be and type **go mod init <module name>. This will create a go.mod file in the folder. The module name does not need to match the folder name
  2. Inside go.mod, the file should look like this:
module mymodule
go 1.16