amazon-web-services - AWS CodeBuild golang 构建失败
问题描述
当我运行以下命令时:- go build -o app
我收到以下错误(对于多个依赖项):main.go:21:2: cannot find package "github.com/gorilla/mux" in any of:
/usr/local/go/src/github.com/gorilla/mux (from $GOROOT)
/go/src/github.com/gorilla/mux (from $GOPATH)
/codebuild/output/src324986171/src/github.com/gorilla/mux
意味着代码构建失败。知道如何解决这个问题,或者一般来说问题出在哪里?谢谢你的帮助。
编辑:添加go get ./...
到构建后,我的所有本地包都出现以下错误:# cd .; git clone https://github.com/aristotle/dbhelper /go/src/github.com/aristotle/dbhelper
Cloning into '/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
解决方案
根据这篇文章,您需要将其添加到文件的install
部分buildspec.yml
。
install:
commands:
- go get github.com/gorilla/mux
也许包含它也go get ./...
可以解决所有依赖关系......但如果你没有太多,那么明确列出它们是一个好习惯。
这是源文章:https ://www.contributing.md/2017/06/30/golang-with-aws-codebuild/
推荐阅读
- c# - 如何使用 c# 连接到 phpmyadmin mysql 数据库(使用 Mysql.Data.MysqlClient;)
- chart.js - 可以用 ChartJS 创建象限图,“原点”集中在一个点上吗?
- sql-server - SSIS 数据转换失败。将全为“00000000”的字段导入字符字段时可能丢失数据
- azure-web-app-service - 选择节点版本时权限被拒绝的部署问题
- android - 应用程序关闭后,工作变量被销毁
- mongodb - 当 MongoDB 的文档说 ObjectID“可能是唯一的”时,它是什么意思?
- javascript - 防止 Webpack 删除 jQuery 函数?
- asp.net-core - 配置 OData 测试服务器
- ios - Scenekit 场景需要太长时间才能显示在视图上
- react-native - React Native 在上下文状态更改后不会重新渲染