Google App Engine环境中托管的Golang网络应用程序出错;应用程序前端BigQuery [英] Errors with a Golang web app hosted in a Google App Engine environment; the app front-ends BigQuery

查看:187
本文介绍了Google App Engine环境中托管的Golang网络应用程序出错;应用程序前端BigQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个Golang Web应用程序,该应用程序以Google BigQuery项目为前端。应用程序有这些导入

  import(
context
html / template
log
net / http
regexp
字符串
strconv
cloud.google.com/go/bigquery
google.golang.org/api/iterator

和a用于BigQuery安全证书的JSON文件。本地,它在localhost:8080完美工作。然后,我尝试使用Google App Engine托管它,并且遇到了一些错误。



对于Google App Engine部署,我首先在本地安装Google Cloud SDK,然后运行gcloud init ,并安装了

  gcloud组件安装app-engine-go 
bq
核心
gsutil
gcloud
beta
app-engine-python

包。我从main.go中删除了main()函数,并且项目目录中有一个YAML文件。我跑了

  gcloud config set project {正确的项目ID} 

在DOS窗口中,我运行了

  gcloud app deploy 

在项目目录中。我得到了这个错误(格式化为SO,并删除私人信息):

  C:\Golang Web Dev \golang- web-dev-master\bigqueryApp_AppEngine> gcloud应用程序部署

错误:(gcloud.app.deploy)
分段命令

[C:\程序文件(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\ -------- \ --------]

返回码[1]失败。

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

2017/07/18 18:14:44分析失败C:\Golang Web Dev \golang-web-dev-master\ bigqueryApp_AppEngine:

在以下任何一项中找不到包google.golang.org/appengine/socket:
($ GOROOT未设置)
C:\ Go Workspace\\ src\google.golang.org\\appeappeine\socket(from $ GOPATH)
GOPATH:C:\ Go Workspace\src\google






我将这个错误追溯到导入的

 cloud.google.com/go/bigquery

包;如果没有cloud.google.com/go/bigquery,另一个测试应用可以正常使用此技术。我尝试导入

  google.golang.org/appengine/socket 

包中的应用程序中,我得到另一个编译错误;它看起来像这个页面说甚至不去那里。接下来,我使用原始应用程序在此视频中尝试了这些想法,将原始主要()函数在main.go中。我键入

  gcloud app deploy 

在云端Shell窗口中。我得到了这个

  $ ---_ ----------- @ -------- ------- X ------:〜/ bigqueryApp 
$ gcloud应用程序部署
错误:(gcloud.app.deploy)暂存命令[/ google / google-cloud-sdk /platform/google_appengine/goroot-1.6/bin/go-app-stager
/home/---_---------/bigqueryApp/app.yaml / tmp / ----- ---- / ---------]
失败,返回代码[1]。

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

2017/07/18 21:30:23失败分析/ home / ---_--------- / bigqueryApp:
在以下任何一项中找不到包google.golang.org/api/iterator:
($ GOROOT未设置)
/ home / ---_RY- / gopath / src / google.golang.org / api / iterator(来自$ GOPATH)
/google/gopath/src/google.golang.org/api/iterator
GOPATH:/ home / --- ____- / gopath:/ google / gopath

错误。该应用程序清楚地导入了迭代器包。我研究/实验/等修复这两种技术的错误,但没有运气。如果有人有想法:如何解决这些错误,我想知道他们,我会很感激。



谢谢!

$ b解决方案:

<1>删除context导入

$ b
$ b

解决方案


$ b

2)导入google.golang.org/appengine;见

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

了解更多详情re:本地appengine软件包安装



3)这个函数

  http.HandleFunc(/,bqPage)

调用

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

作为处理函数。将第二个req参数传递给构建/调用bigquery客户端的代码:

  ctx:= appengine.NewContext(req) 

//从Google云端控制台获取projectID值:

projectID:=--------------

//创建一个客户端。

client,err:= bigquery.NewClient(ctx,projectID)

一旦你有了客户端对象,你就可以开始工作了。



4)从DOS窗口指向托管main.go文件的目录,运行

  gcloud app deploy 



<然后以

运行应用程序

  gcloud应用程序浏览


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!

解决方案

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

这篇关于Google App Engine环境中托管的Golang网络应用程序出错;应用程序前端BigQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆