我是Google App Engine的新手。 而且,我遇到了无法解决的问题。
我有一个非常简单的应用程序(在Go中开发),如下所示:
main/
| model/
| | user.go
| main.go
| app.yaml
这些是main.go的导入:
import (
"github.com/julienschmidt/httprouter"
"log"
"net/http"
)
我的代码在本地运行时效果很好。
但是,当我尝试将其发布到我的Google App Engine实例上时,出现此错误:
$ gcloud app deploy
You are about to deploy the following services:
- <MY_APP_ENGINE_URL> (from [<MY_LOCAL_YAML_PATH>])
Deploying to URL: [<MY_APP_ENGINE_URL>]
Do you want to continue (Y/n)? Y
Beginning deployment of service [default]...
Some files were skipped. Pass `--verbosity=info` to see which ones.
You may also view the gcloud log file, found at
[<LOCAL_APP_ENGINE_LOG>].
File upload done.
Updating service [default]...failed.
ERROR: (gcloud.app.deploy) Error Response: [9] Deployment contains files that cannot be compiled: Compile failed:
2017/05/27 14:48:24 go-app-builder: build timing: 5×compile (301ms total), 0×link (0s total)
2017/05/27 14:48:24 go-app-builder: failed running compile: exit status 2
main.go:4: can't find import: "github.com/julienschmidt/httprouter"
我做错了什么 ?
编辑:这是我的app.yaml文件的内容:
runtime: go
api_version: go1
handlers:
- url: /.*
script: _go_app
App Engine环境不包含您的依赖项,您可以为每个添加一个脚本来执行go get ...,但是它太过hacky,而Go有一个解决方案,我们可以将依赖项保存在根目录下的vendor文件夹中我们的项目。
快速解决方案 :
# Instal godep:
go get -v -u github.com/tools/godep
cd your/project/path
godep save
现在尝试再次部署,您将在项目中看到一个vendor文件夹,不要将其删除并将其添加到您的git源中,该文件夹包含您的所有第三方依赖项,例如您的httprouter(这是我的最爱:))
注意您可以使用其他工具来保存您的依赖项
我还没有使用过gcloud
工具,但是在goapp
曾经是您必须在您的main
下直接创建github.com/julienschmidt/httprouter
(当然,其中包含lib的源代码)的工具之前, 。
AFAIK App Engine的go版本当前为1.6,这意味着虽然默认情况下启用了供应商,但可以将其关闭-也许是这样,这就是@Yandry Pozo的建议不起作用的原因。