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

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

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 并将其作为导入时,它给我一个错误:

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

makefile:

SHELL = /bin/bash
OS = $(shell uname -s)
PACKAGE = github.com/username/scheduler
BINARY_NAME = scheduler
IMAGE = name
TAG = tagsvalue

BUILD_DIR ?= build
BUILD_PACKAGE = ${PACKAGE}/cmd/scheduler
DEP_VERSION = 0.5.0
GOLANG_VERSION = 1.11

.PHONY: clean
clean: ## Clean the working area and the project
       rm -rf bin/ ${BUILD_DIR}/ vendor/
       rm -rf ${BINARY_NAME}

bin/dep: bin/dep-${DEP_VERSION}
       @ln -sf dep-${DEP_VERSION} bin/dep
bin/dep-${DEP_VERSION}:
        @mkdir -p bin
        curl https://raw.githubusercontent.com/golang/dep/master/install.sh |   INSTALL_DIRECTORY=bin DEP_RELEASE_TAG=v${DEP_VERSION} sh
        @mv bin/dep $@

.PHONY: vendor
vendor: bin/dep ## Install dependencies
       bin/dep ensure -v -vendor-only

.PHONY: build
build: ## Build a binary
        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:

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

makefile:

    SHELL = /bin/bash
    OS = $(shell uname -s)
    PACKAGE = github.com/username/scheduler
    BINARY_NAME = scheduler
    IMAGE = name
    TAG = tagsvalue
    
    BUILD_DIR ?= build
    BUILD_PACKAGE = ${PACKAGE}/cmd/scheduler
    DEP_VERSION = 0.5.0
    GOLANG_VERSION = 1.11

    .PHONY: clean
    clean: ## Clean the working area and the project
           rm -rf bin/ ${BUILD_DIR}/ vendor/
           rm -rf ${BINARY_NAME}

    bin/dep: bin/dep-${DEP_VERSION}
           @ln -sf dep-${DEP_VERSION} bin/dep
   bin/dep-${DEP_VERSION}:
            @mkdir -p bin
            curl https://raw.githubusercontent.com/golang/dep/master/install.sh |   INSTALL_DIRECTORY=bin DEP_RELEASE_TAG=v${DEP_VERSION} sh
            @mv bin/dep $@

    .PHONY: vendor
    vendor: bin/dep ## Install dependencies
           bin/dep ensure -v -vendor-only

    .PHONY: build
    build: ## Build a binary
            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。使用模块非常容易:

$ cd ~
$ mkdir new_project
& cd new_project
# 初始化模块
$ go mod init github.com/user/new_project
$ ls
go.mod
$ cat go.mod
module github.com/user/new_project

go 1.19
# mod文件中的版本将反映您本地安装的Go版本

现在添加依赖项:

$ go get github.com/jinzhu/copier
# 检查:
$ ls
go.mod    go.sum
$ cat go.mod
module github.com/user/new_project

go 1.19

require github.com/jinzhu/copier v0.3.5 // indirect

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

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

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

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

module github.com/user/new_project

go 1.19

require (
   github.com/jinzhu/copier v0.3.2
   github.com/foo/bar
)

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

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

$ go build .

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

$ go mod download

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

$ 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:

$ cd ~
$ mkdir new_project
& cd new_project
# initialise module
$ go mod init github.com/user/new_project
$ ls
go.mod
$ cat go.mod
module github.com/user/new_project

go 1.19
# the version in the mod file will reflect the version of go you have installed locally

Now to add dependencies:

$ go get github.com/jinzhu/copier
# check:
$ ls
go.mod    go.sum
$ cat go.mod
module github.com/user/new_project

go 1.19

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:

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

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

module github.com/user/new_project

go 1.19

require (
   github.com/jinzhu/copier v0.3.2
   github.com/foo/bar
)

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

Now you can just compile your code:

$ 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:

$ go mod download

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

$ 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:

确定