Version Selection Algorithm
When a project has dependencies on the same third-party package with inconsistent versions, Go Modules
uses the "minimal version selection algorithm" (The minimal version selection algorithm
: https://github.com/golang/go/wiki/Modules#version-selection).
For example, if your module depends on module A with require D v1.0.0
, and also depends on module B with require D v1.1.1
, the minimal version selection will choose version v1.1.1
of D for building (using the highest version).
Please don't ask why this algorithm is called the "minimal version selection algorithm," yet it resembles a "highest version selection algorithm." If you have any concerns about this, feel free to raise an issue with the official: https://github.com/golang/go/issues
Private Dependency Management
If you can perfectly manage your project package dependencies via go.mod
, you may skip this section. If you encounter issues with package dependency management in projects, it is suggested that you continue reading for inspiration on problem-solving.
In the preceding sections, we provided a very detailed, illustrated guide on the installation/configuration of the development environment and the installation/use of Go Module
. In actual project development, you may come across more issues, commonly:
- Although
GoFrame
is powerful, most of the time the dependencies include not onlyGoFrame
but also some additional third-party packages, especially packages fromgolang.org
, which may require a proxy for downloading. This can be handled locally more easily, but may cause some inconvenience on automated deployment systems; - Some self-developed third-party packages, particularly business-specific packages, cannot be publicly downloaded (private libraries), and the version control system might not support the
HTTPS
protocol, making it impossible to usego get
orgo.mod
for downloading and managing; - Etc.
If you encounter the above issues, we recommend setting valid domains for private packages through GOPRIVATE
.
For example, the following command-line approach:
export GOPROXY=https://goproxy.cn
export GOPRIVATE=git.xxx.com
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main main.go
This feature requires
Go v1.13
or higher.
Set it up in Goland
as follows: