go run <module-path>/<module-name>.go
For building a go module, the module must be inside the directory defined by GOPATH env variable, where GOPATH has the following structure:
$GOPATH
├── bin
├── lib
└── src
and modules are located inside the 'src' directory Run the following command to build a module
go build <module-name>
This will generate a binary calling directory.
Installing a go module refers to installing it to bin directory in the GOPATH. To install a module:
go install <module-name>
Golang needs to run inside path pointed by GOPATH env variable. To update the GOPATH to use the current directory, run the following command:
On linux, source the file:
. set_gopath.sh
On Windows, run:
.\set-gopath.ps1
GOPATH env variable can have multiple paths, so its better to add the workspace to GOPATH in .profile in linux and env variables in Windows
This work has been taken from multiple sources, combined into one for a quick study. I do not take ownership for any part, except for the bash and pwsh scripts