cannot find package "k8s.io/metrics/pkg/client/clientset/versioned" in any of:Vendor , GOROOT , GOPATH

huangapple go评论122阅读模式
英文:

cannot find package "k8s.io/metrics/pkg/client/clientset/versioned" in any of:Vendor , GOROOT , GOPATH

问题

我正在尝试创建一个调度程序,所以在编写代码和创建部署后,我使用一个 makefile 来构建并使用 vendor。但是当我使用第一个代码时,它使用与 GitHub 代码库中的代码相同的导入,它可以工作。但是当我添加了 k8s.io/metrics/pkg/client/clientset/versioned 并将其作为导入时,它给我一个错误:

  1. cmd/scheduler/main.go:24:5: cannot find package "k8s.io/metrics/pkg/client/clientset/versioned" in any of:
  2. /go/src/github.com/username/scheduler/vendor/k8s.io/metrics/pkg/client/clientset/versioned (vendor tree)
  3. /usr/local/go/src/k8s.io/metrics/pkg/client/clientset/versioned (from $GOROOT)
  4. /go/src/k8s.io/metrics/pkg/client/clientset/versioned (from $GOPATH)

makefile:

  1. SHELL = /bin/bash
  2. OS = $(shell uname -s)
  3. PACKAGE = github.com/username/scheduler
  4. BINARY_NAME = scheduler
  5. IMAGE = name
  6. TAG = tagsvalue
  7. BUILD_DIR ?= build
  8. BUILD_PACKAGE = ${PACKAGE}/cmd/scheduler
  9. DEP_VERSION = 0.5.0
  10. GOLANG_VERSION = 1.11
  11. .PHONY: clean
  12. clean: ## Clean the working area and the project
  13. rm -rf bin/ ${BUILD_DIR}/ vendor/
  14. rm -rf ${BINARY_NAME}
  15. bin/dep: bin/dep-${DEP_VERSION}
  16. @ln -sf dep-${DEP_VERSION} bin/dep
  17. bin/dep-${DEP_VERSION}:
  18. @mkdir -p bin
  19. curl https://raw.githubusercontent.com/golang/dep/master/install.sh | INSTALL_DIRECTORY=bin DEP_RELEASE_TAG=v${DEP_VERSION} sh
  20. @mv bin/dep $@
  21. .PHONY: vendor
  22. vendor: bin/dep ## Install dependencies
  23. bin/dep ensure -v -vendor-only
  24. .PHONY: build
  25. build: ## Build a binary
  26. go build ${BUILD_PACKAGE}

请帮助我,我知道问题不太清楚,但我是 Go 语言的新手,任何信息都会有所帮助。谢谢。

英文:

I am trying to create i scheduler so after writing the code and creating deployment i use a make file to build and use vendor also but when i use my first code which use the same imports as the code in github reposetory it works but when i add to it and use k8s.io/metrics/pkg/client/clientset/versioned as import it give me an error:

  1. cmd/scheduler/main.go:24:5: cannot find package "k8s.io/metrics/pkg/client/clientset/versioned" in any of:
  2. /go/src/github.com/username/scheduler/vendor/k8s.io/metrics/pkg/client/clientset/versioned (vendor tree)
  3. /usr/local/go/src/k8s.io/metrics/pkg/client/clientset/versioned (from $GOROOT)
  4. /go/src/k8s.io/metrics/pkg/client/clientset/versioned (from $GOPATH)

makefile:

  1. SHELL = /bin/bash
  2. OS = $(shell uname -s)
  3. PACKAGE = github.com/username/scheduler
  4. BINARY_NAME = scheduler
  5. IMAGE = name
  6. TAG = tagsvalue
  7. BUILD_DIR ?= build
  8. BUILD_PACKAGE = ${PACKAGE}/cmd/scheduler
  9. DEP_VERSION = 0.5.0
  10. GOLANG_VERSION = 1.11
  11. .PHONY: clean
  12. clean: ## Clean the working area and the project
  13. rm -rf bin/ ${BUILD_DIR}/ vendor/
  14. rm -rf ${BINARY_NAME}
  15. bin/dep: bin/dep-${DEP_VERSION}
  16. @ln -sf dep-${DEP_VERSION} bin/dep
  17. bin/dep-${DEP_VERSION}:
  18. @mkdir -p bin
  19. curl https://raw.githubusercontent.com/golang/dep/master/install.sh | INSTALL_DIRECTORY=bin DEP_RELEASE_TAG=v${DEP_VERSION} sh
  20. @mv bin/dep $@
  21. .PHONY: vendor
  22. vendor: bin/dep ## Install dependencies
  23. bin/dep ensure -v -vendor-only
  24. .PHONY: build
  25. build: ## Build a binary
  26. go build ${BUILD_PACKAGE}

please help i know that the question is not to clear but i am a new to golang so any information will help. thank you

答案1

得分: 0

好的,我会为你翻译这段内容。以下是翻译的结果:

好的,既然你想知道如何使用Go模块,我会写一个简要的总结。完整的文档在这里,在go.dev网站上。很容易找到,并且会指导你从头到尾完成整个过程。


自从引入了Go模块以来,我一直将其作为我的主要语言,可以诚实地说,我很少需要使用Makefile。使用模块非常容易:

  1. $ cd ~
  2. $ mkdir new_project
  3. & cd new_project
  4. # 初始化模块
  5. $ go mod init github.com/user/new_project
  6. $ ls
  7. go.mod
  8. $ cat go.mod
  9. module github.com/user/new_project
  10. go 1.19
  11. # mod文件中的版本将反映您本地安装的Go版本

现在添加依赖项:

  1. $ go get github.com/jinzhu/copier
  2. # 检查:
  3. $ ls
  4. go.mod go.sum
  5. $ cat go.mod
  6. module github.com/user/new_project
  7. go 1.19
  8. require github.com/jinzhu/copier v0.3.5 // indirect

依赖项已添加,并创建了一个go.sum文件。这充当了您的依赖项的锁定文件。它基本上是您项目中使用的确切版本的提交哈希。

您可以指定特定版本(比如我们想要版本v0.3.2而不是0.3.5),只需使用以下命令:

  1. $ go get github.com/jinzhu/copier@v0.3.2

或者您可以在编辑器中手动向mod文件添加依赖项:

  1. module github.com/user/new_project
  2. go 1.19
  3. require (
  4. github.com/jinzhu/copier v0.3.2
  5. github.com/foo/bar
  6. )

等等。查看文档以了解replacerequire_test等内容以及它们的作用。

现在,您只需编译您的代码:

  1. $ go build .

您尚未下载的任何依赖项将自动进行检查、更新和下载。如果您想手动下载依赖项,可以执行以下操作:

  1. $ go mod download

如果您想删除不再使用的依赖项(即清理go.sum文件):

  1. $ go mod tidy

实际上,没有更多的内容了。

英文:

Alright, seeing as you want to know how to use go modules, I'll write a brief summary. The full documentation is here, on the go.dev site. It's easy to find, and walks you through the entire process beginning to end.


I have been using go as my main language since go 1.4. Since the introductions of go modules, I can honestly say that I rarely, if ever, need a Makefile. To use modules is fantastically easy:

  1. $ cd ~
  2. $ mkdir new_project
  3. & cd new_project
  4. # initialise module
  5. $ go mod init github.com/user/new_project
  6. $ ls
  7. go.mod
  8. $ cat go.mod
  9. module github.com/user/new_project
  10. go 1.19
  11. # the version in the mod file will reflect the version of go you have installed locally

Now to add dependencies:

  1. $ go get github.com/jinzhu/copier
  2. # check:
  3. $ ls
  4. go.mod go.sum
  5. $ cat go.mod
  6. module github.com/user/new_project
  7. go 1.19
  8. require github.com/jinzhu/copier v0.3.5 // indirect

The dependency was added, and a go.sum file is created. This acts as a lock file for your dependencies. It's basically the commit hash of the exact version used in your project.

You can specify a specific version (saw we want version v0.3.2 instead of 0.3.5), you can just use the command:

  1. $ go get github.com/jinzhu/copier@v0.3.2

Or you can manually add dependencies to your mod file in your editor:

  1. module github.com/user/new_project
  2. go 1.19
  3. require (
  4. github.com/jinzhu/copier v0.3.2
  5. github.com/foo/bar
  6. )

And so on. Check the docs for things like replace and require_test, and what they do.

Now you can just compile your code:

  1. $ go build .

Any dependencies that you haven't downloaded yet will be automatically checked and updated/downloaded for you. If you want to download the dependencies manually, you can:

  1. $ go mod download

If you want to remove dependencies that are no longer in use (ie clean up the go.sum file):

  1. $ go mod tidy

There's nothing more to it, really.

huangapple
  • 本文由 发表于 2022年10月19日 22:13:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/74126914.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定