GOROOT is a variable that defines where your Go SDK (installation) is located. You do not need to change this variable, unless you plan to use different Go versions. To find the GOPATH location, type go env:
/usr/local/go/%PROGRAMFILES%/goGOPATH is a variable that defines the root of your Workspace, where all Go code is organized to store your codebase. To find the GOPATH location, type go env:
/home/user/go/ or ~/go%USERPROFILE%/go~/go/src/ - source code location~/go/pkg/ - shared libraries location~/go/bin/ - compiled code location.png)
*.mod file because Go wanted to enforce one centralized location for managing packages in the /pkg directory that the GOPATH looks for. However, people started complaining that in their /src path, they can’t separate different versions or have isolated environments (even though renaming folders could fix this easily).GOPATH that automagically switches on top of the current gopath. The gopath still exists in order to be backwards compatible. Each time you go to a module folder with a *.mod file, you can type go env in your terminal and see the gomod environment variable magically change to the current folder where the module is and the gopath will remain the same.GOPATH/pkg is where Go stores pre-compiled object files to speed up subsequent compiling of programs, they had no choice but to create a second subfolder for isolation. And the /mod folder functions the same way as /pkg, but just separated from the rest to avoid version conflicts but still benefit from the fast compilation times within a higher hierarchy. It is by design to keep compilation centralized, yet decoupled for modules.
A module has many projects. Modules are isolated workspaces, decoupled from the gopath. This is useful if many code-bases exist on different systems.
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 namego.mod, the file should look like this:module mymodule
go 1.16