构建aws-sdk-go的依赖关系在Go版本1.13上失败

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了构建aws-sdk-go的依赖关系在Go版本1.13上失败相关的知识,希望对你有一定的参考价值。

我一直在尝试在Go v1.13上构建一个模块,该模块依赖于github.com/aws/aws-lambda-gogithub.com/aws/aws-sdk-go,这在两次导入时均失败:

    "github.com/aws/aws-sdk-go/aws/service/s3"
    "github.com/aws/aws-sdk-go/aws/service/s3/s3manager"

对于GOOS=linux GOARCH=amd64 go build -o dist/api ./api,stderr如下,其中api目录包含我的模块定义:

api/main.go:11:2: cannot find package "github.com/aws/aws-sdk-go/aws/service/s3" in any of:
        /usr/local/go/src/github.com/aws/aws-sdk-go/aws/service/s3 (from $GOROOT)
        /u/go/src/github.com/aws/aws-sdk-go/aws/service/s3 (from $GOPATH)
api/main.go:12:2: cannot find package "github.com/aws/aws-sdk-go/aws/service/s3/s3manager" in any of:
        /usr/local/go/src/github.com/aws/aws-sdk-go/aws/service/s3/s3manager (from $GOROOT)
        /u/go/src/github.com/aws/aws-sdk-go/aws/service/s3/s3manager (from $GOPATH)

老实说,我不知道为什么会这样,任何输入都会受到赞赏。

已经尝试使用go get来确保已删除依赖项:

$ go get github.com/aws/aws-sdk-go

并且所请求的导入路径位于$GOPATH/src/github.com/aws/aws-sdk/go/aws/service/s3$GOPATH/src/github.com/aws/aws-sdk/go/aws/service/s3/s3manager

此外,还尝试使用go clean --cache --modcache清除缓存,同时删除先前拉出的模块。

[仔细检查,我完全忽略了一点,导入路径是/u/go/src/github.com/aws/aws-sdk-go/aws/service/s3而不是/u/go/src/github.com/aws/aws-sdk-go/service/s3,而前者在aws内有一个附加的aws-sdk-go子路径。

答案

刚刚意识到我在代码中犯的复制/粘贴错误。

import (
    "github.com/aws/aws-sdk-go/aws/service/s3"
    "github.com/aws/aws-sdk-go/aws/service/s3/s3manager"
)

而不是

import (
    "github.com/aws/aws-sdk-go/service/s3"
    "github.com/aws/aws-sdk-go/service/s3/s3manager"
)

以上是关于构建aws-sdk-go的依赖关系在Go版本1.13上失败的主要内容,如果未能解决你的问题,请参考以下文章

golang aws-sdk-go 之 s3 服务

当***模块及其子模块之一作为单独版本单独导入时,如何解决冲突的 go 模块依赖关系?

go.sum工作机制

go官方包依赖管理工具之mod

go官方包依赖管理工具之mod

使用 golang 从 DynamoDB 获取记录时出现紧急运行时错误