去 mod 供应商 returns "all matched no packages"

go mod vendor returns "all matched no packages"

我正在尝试设置一个新的存储库,其中将包含一些后端服务,名为 backend。我创建了 repo,将其克隆到 /home/me/go/src/github.com/myrepo/backend。然后我做了以下事情:

$ go mod init backend
go: creating new go.mod: module backend
go: to add module requirements and sums:
    go mod tidy

$ go mod tidy
go: warning: "all" matched no packages

$ go get -u github.com/snowflakedb/gosnowflake
go: downloading...

$ go mod vendor
go: warning: "all" matched no packages

所有这些之后,/vendor/ 目录只包含 modules.txt 而我的 go.mod 文件如下所示:

$ cat go.mod
module backend

go 1.18

require (
    github.com/Azure/azure-pipeline-go v0.2.3 // indirect
    github.com/Azure/azure-storage-blob-go v0.15.0 // indirect
    github.com/apache/arrow/go/arrow v0.0.0-20211112161151-bc219186db40 // indirect
    github.com/aws/aws-sdk-go-v2 v1.16.3 // indirect
    github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.1 // indirect
    github.com/aws/aws-sdk-go-v2/credentials v1.12.1 // indirect
    github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.11 // indirect
    github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.10 // indirect
    github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.4 // indirect
    github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.1 // indirect
    github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.1 // indirect
    github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.5 // indirect
    github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.4 // indirect
    github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.4 // indirect
    github.com/aws/aws-sdk-go-v2/service/s3 v1.26.9 // indirect
    github.com/aws/smithy-go v1.11.2 // indirect
    github.com/form3tech-oss/jwt-go v3.2.5+incompatible // indirect
    github.com/gabriel-vasile/mimetype v1.4.0 // indirect
    github.com/google/flatbuffers v2.0.6+incompatible // indirect
    github.com/google/uuid v1.3.0 // indirect
    github.com/jmespath/go-jmespath v0.4.0 // indirect
    github.com/klauspost/compress v1.15.4 // indirect
    github.com/mattn/go-ieproxy v0.0.6 // indirect
    github.com/pierrec/lz4/v4 v4.1.14 // indirect
    github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
    github.com/sirupsen/logrus v1.8.1 // indirect
    github.com/snowflakedb/gosnowflake v1.6.9 // indirect
    golang.org/x/crypto v0.0.0-20220516162934-403b01795ae8 // indirect
    golang.org/x/net v0.0.0-20220516155154-20f960328961 // indirect
    golang.org/x/sys v0.0.0-20220513210249-45d2b4557a2a // indirect
    golang.org/x/text v0.3.7 // indirect
    golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
}

当我 go env 我得到:

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/me/.cache/go-build"
GOENV="/home/me/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS="-mod=vendor"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/me/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/me/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.18"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.18/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/me/go/src/github.com/myrepo/backend/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2382531553=/tmp/go-build -gno-record-gcc-switches"`

我环顾四周,发现 this question 但是,由于我的模块没有隐藏标准库包,而且我实际上还没有在其中编写任何 Golang 代码,所以我认为这不是问题。所以,我的问题是:为什么我会收到此警告,我应该怎么做,以及如何在 /vendor/ 中缓存 go.mod 中引用的包?

正如@JimB 所指出的,核心问题是我还没有在模块中编写任何代码。一旦我添加了一些代码,警告就消失了。