In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article shows you how to use the management tool go modules, which is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Background
Because before writing k8s operator in the introduction of go package, involving go package management tools, because I have been writing java for many years, maven package management tools are very easy to use, so I wonder whether golang also has similar tools. Goer knows that go packages are introduced with a github.com-like prefix, so they will automatically download the corresponding files from go's third-party retrieval service pkg.go.dev, which regularly updates the latest code from github.
Go mod was introduced in golang version 1.11. Compared with before, either there is no package management, or the management tools are not easy to use.
Use
Check the version of golang and make sure you have go version go version go1.15.2 darwin/amd64 at version 1.11 or above
Setting GO111MODULE to on GO111MODULE has three values: off,on,auto (default)
Off turns off the go mod function and looks for packages in the same GOPATH mode or through the vendor directory.
On enables the go mod function and will not look up the GOPATH directory
Auto, by case
If the current directory is outside GOPATH/src and the directory contains go.mod files, the go mod function will be enabled.
The current file is under the directory that contains the go.mod file
If the initialization project executes go mod init directly under the current project, a go.mod file will be created under the current project. If the project is in the GOPATH directory and GO111MODULE is not set to on, an error will be reported:
Go: modules disabled inside GOPATH/src by GO111MODULE=auto; see'go help modules'
Executing go build will automatically add the dependent files of the project to the go.mod and generate the go.sum file
If there is a package dependency flushing problem, modify directly and follow the prompts to modify the corresponding version of the go.mod file. Such as:
.. / pkg/mod/k8s.io/client-go@v11.0.0+incompatible/kubernetes/scheme/register.go:26:2: module k8s.io/api@latest found (v0.19.4) But does not contain package k8s.io/api/auditregistration/v1alpha1go.mod module github.com/monkeyboy123/custom-controllergo 1.15require (github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b github.com/imdario/mergo v0.3.11 / / indirect golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e / / indirect k8s.io/api v0.19.4 / / indirect k8s.io/apimachinery v0.19.4 K8s.io/client-go v11.0.0+incompatible k8s.io/klog v1.0.0 / / indirect k8s.io/utils v0.0.0-20201110183641-67b214c5f920 / / indirect)
Directly modify k8s.io/client-go v11.0.0+incompatible to k8s.io/client-go v0.19.4
For go mod management, downloads of dependency packages go to the $GOPATH/pkg/mod directory instead of the $GOPATH/src directory
The above content is how to use the management tool go modules. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.