当我运行以下命令时:- go build -o app
我收到以下错误(针对多个依赖项):main.go:21:2: cannot find package "github .com/gorilla/mux"在任何一个:
/usr/local/go/src/github.com/gorilla/mux(来自 $GOROOT)
/go/src/github.com/gorilla/mux(来自 $GOPATH)
/codebuild/output/src324986171/src/github.com/gorilla/mux
表示代码构建失败。知道我该如何解决这个问题,或者一般来说问题出在哪里? 感谢您的帮助。
编辑:
将 go get ./...
添加到构建后,我的所有本地包都出现以下错误:# cd .; git 克隆 https://github.com/aristotle/dbhelper/go/src/github.com/aristotle/dbhelper
克隆到 '/go/src/github.com/aristotle/dbhelper'...
我的 buildspec.yml 看起来像这样:
version: 0.2
phases:
install:
commands:
- echo CODEBUILD_SRC_DIR - $CODEBUILD_SRC_DIR
- echo GOPATH - $GOPATH
- echo GOROOT - $GOROOT
build:
commands:
- echo Build started on `date`
- echo Getting packages
- go get ./...
- echo Compiling the Go code...
- go build -o app main.go
post_build:
commands:
- echo Build completed on `date`
artifacts:
files:
- app
最佳答案
根据这篇文章,您需要将它添加到 buildspec.yml
文件的 install
部分。
install:
commands:
- go get github.com/gorilla/mux
也许它也可以包含 go get ./...
这将解决所有依赖关系...但是如果您没有太多依赖关系,最好明确列出它们。
这是文章来源:https://www.contributing.md/2017/06/30/golang-with-aws-codebuild/
关于amazon-web-services - AWS CodeBuild golang 构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52633357/