From e0688df0ff538551c4121e5a578fc91546db445b Mon Sep 17 00:00:00 2001 From: fadyat Date: Mon, 25 Mar 2024 20:32:47 +0300 Subject: [PATCH] feat: go env, go mod refresh --- dump/golang/modules/README.md | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 dump/golang/modules/README.md diff --git a/dump/golang/modules/README.md b/dump/golang/modules/README.md new file mode 100644 index 0000000..654446e --- /dev/null +++ b/dump/golang/modules/README.md @@ -0,0 +1,37 @@ +## GOROOT + +`GOROOT` defines the root directory of the Go SDK and go tools installation. +It is set during the Go installation process. + +Typically, it remains immutable and should not be modified, +except when you intend to use a different version of Go. + +## GOPATH + +`GOPATH` is an environment variable that specifies the location of your Go workspace. +It consists of a colon-separated list of directories where Go searches for source code. + +`GOPATH` was traditionally used for managing dependencies in Go before the introduction of Go Modules. +With Go Modules, setting `GOPATH` is no longer necessary. + +After Go 1.11, `$GOPATH/pkg/mod` is utilized to store all project dependencies, +and `$GOPATH/bin` is used to store binaries generated by `go install`. + +## Go Modules + +Go Modules provide a mechanism for managing dependencies in Go outside the `$GOPATH`. +They enable developers to define, version, and install dependencies more effectively, +reducing reliance on `GOPATH` for dependency management. + +```bash +go mod init github.com/fadyat/ + +# current dependency will be allowed to be used in the project +# and we can find it in go.mod, go.sum and $GOPATH/pkg/mod directory +go get github.com/gorilla/mux + +# installing the binary in $GOPATH/bin directory, but it's +# better to use some prebuilt binaries from the internet +go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.1 +``` +