【问题标题】:Why can't I deploy with 'goapp deploy' to GAE, I get can't find import: "github.com/go-sql-driver/mysql"为什么我不能使用“goapp deploy”部署到 GAE,我找不到导入:“github.com/go-sql-driver/mysql”
【发布时间】:2014-05-05 15:52:59
【问题描述】:

主要问题:无法使用“goapp deploy”部署到 GAE,不断收到此消息:

src/mygoprog.go:11:找不到导入:“github.com/go-sql-driver/mysql”

我已经部署了“hello world”程序,它在端口 8080 上监听 GAE 没有任何问题;现在正在尝试部署一个更复杂的程序。

这可以很好地在本地测试: C:\mysql\src>去运行mygoprog.go

这在尝试部署到 GAE 时不会: C:\mysql>goapp 部署

我已经从头开始重新安装了 goappengine 和 go 语言,并在卸载和安装之间清理了注册表。 任何帮助将不胜感激。

github 安装命令: goapp 获取 github.com/go-sql-driver/mysql 也试过 去获取github.com/go-sql-driver/mysql

源代码(我试过移动它,错误跟随移动到第 11 行或第 2 行或其他):

import (
    "database/sql"
    "io/ioutil"
    "encoding/json"
    "fmt"
    "net/http"
    "log"
)
import  _ "github.com/go-sql-driver/mysql"

环境: 蟒蛇 2.7 视窗 7 - 64 位 goappengine sdk 版本 1.9.1 水银 2.9.1

环境变量: GOPATH=C:\mysql\ GOROOT=C:\Go\

app.yml 内容: 申请:熟练的国家521 版本:1 运行时:去 api_version: go1

处理程序: - 网址:/.* 脚本:_go_app

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 这不起作用: C:\mysql>goapp 部署

Results:
05:20 PM Application: skilled-nation-521; version: 1
05:20 PM Host: appengine.google.com
05:20 PM
Starting update of app: skilled-nation-521, version: 1
05:20 PM Getting current resource limits.
05:20 PM Scanning files on local disk.
05:20 PM Cloning 23 application files.
05:20 PM Compilation starting.
05:20 PM Compilation: 16 files left.
05:20 PM Error 422: --- begin server output ---
Compile failed:
2014/03/26 15:20:24 go-app-builder: build timing: 2├ù6g (171.487931ms total), 2├gopack (61.001119ms total), 0├ù6l (0 total)
2014/03/26 15:20:24 go-app-builder: failed running 6g: exit status 1



src/mygoprog.go:11: can't find import: "github.com/go-sql-driver/mysql"
--- end server output ---
05:20 PM Rolling back the update.
Error 422: --- begin server output ---

--- 结束服务器输出 --- 运行 appcfg.py 时出错:退出状态 1

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ c:\mysql的目录结构:

C:\mysql>dir
 Volume in drive C is OS
 Volume Serial Number is D2E8-63AC

 Directory of C:\mysql

03/26/2014  05:14 PM    <DIR>          .
03/26/2014  05:14 PM    <DIR>          ..
03/25/2014  04:17 PM               119 app.yaml
03/26/2014  05:14 PM    <DIR>          pkg
03/26/2014  05:17 PM    <DIR>          src
               1 File(s)            119 bytes
               4 Dir(s)  20,781,137,920 bytes 


C:\mysql>cd src

C:\mysql\src>dir
 Volume in drive C is OS
 Volume Serial Number is D2E8-63AC

 Directory of C:\mysql\src

03/26/2014  05:17 PM    <DIR>          .
03/26/2014  05:17 PM    <DIR>          ..
03/26/2014  05:14 PM    <DIR>          github.com
03/26/2014  05:14 PM             2,666 mygoprog.go
               1 File(s)          2,666 bytes
               3 Dir(s)  20,781,387,776 bytes free

C:\mysql\src>cd github.com

C:\mysql\src\github.com>dir
 Volume in drive C is OS
 Volume Serial Number is D2E8-63AC

 Directory of C:\mysql\src\github.com

03/26/2014  05:14 PM    <DIR>          .
03/26/2014  05:14 PM    <DIR>          ..
03/26/2014  05:14 PM    <DIR>          go-sql-driver
               0 File(s)              0 bytes
               3 Dir(s)  20,781,387,776 bytes free

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

【问题讨论】:

  • 我对 Go 的了解几乎为零(今天早上刚刚听到一个播客),但是看着 golang.org/doc/code.html#PackagePaths 我想知道您在导入语句中包路径之前的下划线是否导致问题?
  • 无论有没有下划线都没有乐趣。网络上那个包的代码示例有下划线。
  • 在 GAE 目录下的 GOAPP.BAT 中设置 GOOS 和 GOARCH,还是不行 C:\mysql>go env set GOARCH=amd64 set GOBIN= set GOCHAR=6 set GOEXE=.exe set GOHOSTARCH =amd64 set GOHOSTOS=windows set GOOS=windows set GOPATH=C:\mysql\ set GORACE= set GOROOT=C:\Go set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64 set TERM=dumb set CC=gcc set GOGCCFLAGS=-g -O2 -m64 -mthreads 设置 CXX=g++ 设置 CGO_ENABLED=1

标签: mysql google-app-engine deployment go


【解决方案1】:

导入路径必须来自 app.yaml 所在的文件夹。所以你需要把 github.com 文件夹移到那里。 (类似问题:How to import local Golang package in GAE

注意:您永远不应该使用 go 可执行文件测试您的 App Engine 内容,始终使用 goapp 工具。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-08
    • 1970-01-01
    • 2016-11-27
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 2021-01-15
    • 2018-08-30
    相关资源
    最近更新 更多