dtgta48604 2017-07-21 04:05
浏览 53
已采纳

在Google App Engine环境中托管的Golang网络应用出现错误; 应用前端BigQuery

I built a Golang web app that front-ends a Google BigQuery project. The app has these imports

import (
      "context"
      "html/template"
      "log"
      "net/http"
      "regexp"
      "strings"
      "strconv"
      "cloud.google.com/go/bigquery"
      "google.golang.org/api/iterator"
)

and a JSON file for the BigQuery security credentials. Locally, it works perfectly at localhost:8080. Then, I tried to host it with Google App Engine and I hit some bugs.

For Google App Engine deployment, I first installed Google Cloud SDK locally, I ran gcloud init, and I installed the

gcloud components install app-engine-go
bq
core
gsutil
gcloud
beta
app-engine-python

packages. I removed the main() function from main.go, and the project directory has a YAML file. I ran

gcloud config set project {correct project ID}

and in a DOS window, I ran

gcloud app deploy

at the project directory. I got this error (formatted for SO and to remove private information):

C:\Golang Web Dev\golang-web-dev-master\bigqueryApp_AppEngine>gcloud app deploy

ERROR: (gcloud.app.deploy)
Staging command

[C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\goapp-stager.exe    
C:\Golang Web Dev\golang-web-dev-master\bigqueryApp_AppEngine\app.yaml    
C:\Golang Web Dev\golang-web-dev-master\bigqueryApp_AppEngine    
c:\-----\-----\appdata\local\temp\--------\--------]

failed with return code [1].

-------------------------------------STDOUT-------------------------------------    
-------------------------------------STDERR-------------------------------------

2017/07/18 18:14:44 failed analyzing C:\Golang Web Dev\golang-web-dev-master\bigqueryApp_AppEngine:

cannot find package "google.golang.org/appengine/socket" in any of:
        ($GOROOT not set)
        C:\Go Workspace\src\google.golang.org\appengine\socket (from $GOPATH)    
GOPATH: C:\Go Workspace\src\google

I traced this bug down to the imported

"cloud.google.com/go/bigquery"

package; another “test” app without cloud.google.com/go/bigquery works OK using this technique. I tried to import the

google.golang.org/appengine/socket

package in the app and I got another compile error; it looks like this page says don’t even go there. Next, I tried the ideas in this vid using the original application, keeping the original main() function in main.go. I typed

gcloud app deploy

in a Cloud Shell window. I got this

$ ---_---------@---------------X------:~/bigqueryApp
$ gcloud app deploy
ERROR: (gcloud.app.deploy) Staging command [/google/google-cloud-sdk/platform/google_appengine/goroot-1.6/bin/go-app-stager
/home/---_---------/bigqueryApp/app.yaml /tmp/---------/---------]
failed with return code [1].

------------------------------------ STDOUT ------------------------------------    
------------------------------------ STDERR ------------------------------------

2017/07/18 21:30:23 failed analyzing /home/---_---------/bigqueryApp:
cannot find package "google.golang.org/api/iterator" in any of:
        ($GOROOT not set)
        /home/---_---------/gopath/src/google.golang.org/api/iterator (from $GOPATH)
        /google/gopath/src/google.golang.org/api/iterator
GOPATH: /home/---_---------/gopath:/google/gopath

error. The app clearly imports the iterator package. I researched / experimented / etc. to fix the bugs in both techniques but no luck. If someone has ideas re: how to fix these bugs, I’d like to know them and I’d be grateful.

Thank you!

  • 写回答

1条回答 默认 最新

  • duanchu7271 2017-07-24 21:38
    关注

    Solution:

    1) Remove the "context" import

    2) Import "google.golang.org/appengine"; see

        [https://github.com/golang/appengine/blob/master/README.md][1]
    

    for more details re: the local appengine package installation

    3) This function

        http.HandleFunc("/", bqPage)
    

    calls

        bqPage(w http.ResponseWriter, req *http.Request)
    

    as the handler function. Pass that second req parameter down to the code that builds / calls the bigquery client:

        ctx := appengine.NewContext(req)
    
        // Get the projectID value from the Google Cloud Console:
    
        projectID := "--------------"
    
        // Create a client.
    
        client, err := bigquery.NewClient(ctx, projectID)
    

    Once you have the client object, you're in business.

    4) From a DOS window pointed to the directory hosting the main.go file, run

        gcloud app deploy
    

    and then run the app with

        gcloud app browse
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败