在以下任何一种中找到包"k8s.io/metrics/pkg/client/clientset/versioned":供应商、GOROOT、GOPATH



我正在尝试创建调度程序,所以在编写代码和创建部署后,我使用make文件来构建和使用供应商,但当我使用与github仓库中的代码使用相同导入的第一个代码时,它可以工作,但当添加到它并使用k8s.io/metrics/pk/client/clientset/versified作为导入时,它会给我一个错误:

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模块,我将写一个简短的摘要。完整的文档在这里,在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/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

真的没有别的了。

最新更新