Avoiding Indirect Dependencies in go.mod
Indirect dependencies in go.mod files arise when your direct dependencies depend on other packages that aren't explicitly specified in your go.mod file. These indirect dependencies are automatically added to your file as you run commands like go build.
Example with Colly
Consider the following go.mod file:
module prodenv go 1.13 require ( github.com/gocolly/colly v1.2.0 )
After running go build, you may notice that the go.mod file contains the following indirect dependencies:
github.com/PuerkitoBio/goquery v1.5.1 // indirect github.com/antchfx/htmlquery v1.2.2 // indirect github.com/antchfx/xmlquery v1.2.3 // indirect github.com/antchfx/xpath v1.1.5 // indirect github.com/gobwas/glob v0.2.3 // indirect github.com/kennygrant/sanitize v1.2.4 // indirect github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect github.com/temoto/robotstxt v1.1.1 // indirect
Explanation
Colly version 1.2.0 does not have a go.mod file, which means all its dependencies are considered indirect. Therefore, when you include Colly in your go.mod, its dependencies are also added as indirect dependencies.
Solution
Unfortunately, there is no way to avoid indirect dependencies entirely. However, there are a few solutions to address this challenge:
The above is the detailed content of How to Avoid Indirect Dependencies in Your `go.mod` File?. For more information, please follow other related articles on the PHP Chinese website!