登录
首页 >  Golang >  Go问答

找不到包“k8s.io/metrics/pkg/client/clientset/versioned”,无法在以下位置之一找到:Vendor、GOROOT、GOPATH

来源:stackoverflow

时间:2024-02-07 12:42:21 125浏览 收藏

一分耕耘,一分收获!既然都打开这篇《找不到包“k8s.io/metrics/pkg/client/clientset/versioned”,无法在以下位置之一找到:Vendor、GOROOT、GOPATH》,就坚持看下去,学下去吧!本文主要会给大家讲到等等知识点,如果大家对本文有好的建议或者看到有不足之处,非常欢迎大家积极提出!在后续文章我会继续更新Golang相关的内容,希望对大家都有所帮助!

问题内容

我正在尝试创建调度程序,因此在编写代码并创建部署后,我也使用 make 文件来构建和使用供应商,但是当我使用我的第一个代码时,它使用与 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)

生成文件:

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}

请帮忙,我知道问题不清楚,但我是 golang 新手,所以任何信息都会有帮助。谢谢


正确答案


好吧,既然你想了解如何使用go模块,我就写一个简单的总结。完整文档为 here,位于 go.dev 网站上。它很容易找到,并引导您完成从头到尾的整个过程。

从 go 1.4 开始我就一直使用 go 作为我的主要语言。自从引入 go 模块以来,我可以诚实地说,我很少(如果有的话)需要 makefile。使用模块非常简单:

$ 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

现在添加依赖项:

$ 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

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

你可以指定一个特定的版本(看到我们想要版本v0.3.2而不是0.3.5),你可以只使用命令:

$ go get github.com/jinzhu/[email protected]

或者您可以在编辑器中手动将依赖项添加到 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

真的没有什么更多的了。

终于介绍完啦!小伙伴们,这篇关于《找不到包“k8s.io/metrics/pkg/client/clientset/versioned”,无法在以下位置之一找到:Vendor、GOROOT、GOPATH》的介绍应该让你收获多多了吧!欢迎大家收藏或分享给更多需要学习的朋友吧~golang学习网公众号也会发布Golang相关知识,快来关注吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>