Errors with the Golang web application hosted in the Google App Engine application environment; BigQuery EndQ FrontQ application

I created a Golang web application that supports the Google BigQuery project. This app has

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 fine on localhost: 8080. Then I tried to host it using the Google App Engine, and I hit some errors.

To deploy the Google App Engine, I first installed the Google Cloud SDK locally, I ran gcloud init and installed

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

packages. I deleted the main () function from main.go, and in the project directory the YAML file. I ran

 gcloud config set project {correct project ID} 

and in the DOS window I launched

 gcloud app deploy 

in the project directory. I got this error (formatted for SO and for deleting personal 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 error to the imported

 "cloud.google.com/go/bigquery" 

package; another โ€œtestโ€ application without cloud.google.com/go/bigquery works fine using this technique. I tried to import

 google.golang.org/appengine/socket 

in the application, and I got another compilation error; it looks like this page says itโ€™s not even there. Then I tried the ideas in this vid using the original application, storing the original main () function in main.go. I typed

 gcloud app deploy 

in the Cloud Shell window. I got it

 $ ---_---------@---------------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 application explicitly imports the iterator package. I researched / experimented / etc. To fix errors in both methods, but no luck. If anyone has ideas: how to fix these errors, Id would like to know them and Id be thankful.

Thanks!

+1
source share
1 answer

Decision:

1) Remove the context import

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

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

for more details: installing a local application package

3) This function

  http.HandleFunc("/", bqPage) 

challenges

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

as a handler function. Pass this second req parameter to the code that creates / 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 a client facility, you are in business.

4) In the DOS window specified in the directory where the main.go file is located, run

  gcloud app deploy 

and then run the application using

  gcloud app browse 
0
source

Source: https://habr.com/ru/post/1265867/


All Articles