build constraint app engine golang - google-app-engine

Im pretty new to go and to the the app engine ,
I got this error cannot find package "appengine" .
so i researched a little bit and i found out about build constraint
cannot find package "appengine/cloudsql"
I tried to solve it by this commands .
go build -v -tags +build appengine
But i got the same error package appengine: cannot find package "appengine" .
I can run the goapp server and deploy app to the app engine
But i cant build or get the auto complete of the app engine library
thanks,
miki

You just need to use -tags appengine, and in the file that needs to just work on appengine you can start it with:
// +build appengine
package someName

Related

Errors with a Golang web app hosted in a Google App Engine environment; the app front-ends 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!
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

Golang Cloud SDK - gcloud app deploy cannot find import package

according to the official documentation for Google App Engine Standard environment (Go API) the "preferred tooling to deploy a project" is now the Cloud SDK and so we moved to gcloud from goapp.
We are unable to deploy Go projects to GAE because all the sub-packages of every given project can't be found at "deploy time".
The typical folder structure that we have been using for every GAE project was as follows:
-project-name
--app.yaml
--main.go
--assets
---package1
---package2
When global libraries were put in the system GOPATH everything worked smoothly.
Running gcloud app deploy we now get this:
You are about to deploy the following services:
- yourproject/default/123456789 (from [/Path/to/app.yaml])
Deploying to URL: [https://yourproject.appspot.com]
Do you want to continue (Y/n)? Y
Beginning deployment of service [default]...
ERROR: (gcloud.app.deploy) Staging command [/path/to/yourproject/app.yaml /var/folders/b6/5ydn0wdn64jd32sxzzz48b7c0000gn/T/tmpbd4oiG] failed with return code [1].
------------------------------------ STDOUT ------------------------------------
------------------------------------ STDERR ------------------------------------
2017/03/24 10:25:58 failed analyzing /path/to/yourproject: cannot find package "yourpackage" in any of:
($GOROOT not set)
/path/to/gopath/src/yourpackage (from $GOPATH)
GOPATH: /path/to/gopath
--------------------------------------------------------------------------------
while dev_appserver.py works perfectly keeping the same folder structure.
Did we miss something?
How can we deploy to Google App Engine Standard environment using gcloud?
If the project structure needs to be changed: how? Is there official documentation about it?
Thanks in advance,
Edit -- Further infos:
Luigi-Mac-Pro:path/to/yourproject distudio$ gcloud version
Google Cloud SDK 148.0.0
app-engine-go
app-engine-go-darwin-x86_64 1.9.50
app-engine-python 1.9.50
bq 2.0.24
bq-nix 2.0.24
core 2017.03.17
core-nix 2016.11.07
gcloud
gcloud-deps 2017.03.17
gcloud-deps-darwin-x86_64 2017.02.21
gsutil 4.23
gsutil-nix 4.22
Google recommends keeping your dependencies outside of the app directory, and using GOPATH to refer them. In your case, that would mean doing the following:
-project-name
--app.yaml
--main.go
where main.go contains
import (
"package1"
"package2"
)
And somewhere else:
-my_packages
--src
---package1
---package2
And then set GOPATH environment variable to path/to/my_packages prior to running dev_appserver and gcloud app deploy.
For the future
We are working out the long term solution for properly vendoring packages inside your app directory – likely using Go's future native package manager. I'm sorry to say that we don't have a good way of supporting sub-packages for gcloud app deploy. This was an unfortunate side effect of compatibility with the App Engine Flexible environment.

how to deploy golang app with dependencies to the app engine with gcloud?

I have an app that uses "github.com/gorilla/mux" and I am able to deploy it with goapp deploy. But I cannot do the same with gcloud preview app deploy because I am facing this error:
Beginning deployment...
Copying files to Google Cloud Storage...
Synchronizing files to [<googlecloudsdk.api_lib.app.cloud_storage.BucketReference object at 0x10514e790>].
File upload done.
Updating module [api]...failed.
ERROR: (gcloud.preview.app.deploy) Error Response: [9] Deployment contains files that cannot be compiled: Compile failed:
2016/03/22 09:06:40 go-app-builder: build timing: 1×6g (42ms total), 0×6l (0 total)
2016/03/22 09:06:40 go-app-builder: failed running 6g: exit status 1
api.go:29: can't find import: "github.com/gorilla/handlers"
I want to be able to do it because I need to deploy from travisCI on merge and I want to use service-client.json for authorisation.
Is there any way around it?
Since Google Cloud SDK 142.0.0 with app-engine-go 1.9.50, you should be able to deploy your application doing
gcloud beta app deploy
This also enables you to use CI/CD tools
To answer your question directly, the way around this would be to use goapp deploy as is recommended by the App Engine documentation for the Go standard environment, Deploying a Go App. At the time when gcloud preview app deploy was available, goapp was recommended precisely for handling go's specific environment and dependency requirements.
Alternatively, if you're looking to use gcloud, you would need to use gcloud app deploy now. gcloud preview app deploy has been deprecated and/or removed as of June 29, 2016.

Google App Engine on PHPStorm 10

I have trouble running/debugging Google App Engine application from PHPStorm lately. It seems that PHPStorm adds a dot ( . ) at the end of the command when running dev_appserver.py
/usr/bin/python /Users/maksim/google-cloud-sdk/platform/google_appengine/dev_appserver.py app.yaml ember.yaml dispatch.yaml --php_executable_path=/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/php55/php-cgi --host=0.0.0.0 --enable_sendmail=true .
dev_appserver.py: error: unrecognized arguments: .
Process finished with exit code 2
When I run the command without dot from my terminal, it is working perfectly.
/usr/bin/python /Users/maksim/google-cloud-sdk/platform/google_appengine/dev_appserver.py app.yaml ember.yaml dispatch.yaml --php_executable_path=/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/php55/php-cgi --host=0.0.0.0 --enable_sendmail=true
How can I fix this? Can JetBrains team update the plugin for Google App Engine or is there a workaround to remove that dot from being added to the script?
EDIT: forgot to add Google App Engine SDK version which is release: "1.9.28"
I encountered a similar problem with PyCharm/python.
Creating a custom Run configuration for my project as suggested in this answer worked for me: Run App Engine development server with modules in PyCharm, a similar solution might work for PHPStorm.

go get | package appengine: unrecognized import path "appengine"

I have a package hosted on github which uses appengine sdk . When I do go get github.com/myself/mynicepackage I get an error
package appengine: unrecognized import path "appengine"
Question : How can I get this package using go get ?
There is no way to download it via go get.
go get works with source code repositories, but Google App Engine SDK is provided via .zip archives.
The only possible way to get Google App Engine SDK is to download it from here and install it manually.

Resources