I'm trying to deploy an API on AppEngine but I'm not sure why it's not working, here's an extract of the code:
package main
import (
"encoding/json"
"io/ioutil"
"net/http"
"fmt"
"google.golang.org/appengine"
)
func main () {
InitPubSub()
http.HandleFunc("/", HandlerBase)
http.HandleFunc("/user", HandlerUser)
http.HandleFunc("/event", HandlerEvent)
appengine.Main()
}
I'm getting the following error when I try to deploy the app (gcloud app deploy): main.go:9: can't find import: "google.golang.org/appengine"
I've followed the installation guide: https://cloud.google.com/appengine/docs/standard/go/download
And downloaded the appengine package: go get google.golang.org/appengine
Thanks!
Quoted from the Google App Engine forum:
"Developers are aware of this issue and are actively contributing towards a solid solution to it. In the meanwhile, you should be able to use "goapp deploy" instead of the gcloud command."
I had this problem too when I was following: https://cloud.google.com/appengine/docs/standard/go/tools/using-local-server
What worked for me was replacing
import "google.golang.org/appengine"
with:
import "appengine"
I'm not sure if the instruction is outdated.
To run a go appengine project, I found this project structure for a single service more than enough.
your/project/path/src/mainapp.go
your/project/path/src/app.yaml
or
your/project/path/src/mainfolder/mainapp.go
your/project/path/src/mainfolder/app.yaml
your/project/path/src/lib/lib1/watever.go
your/project/path/src/lib/lib2/whatever2.go
your/project/path/src/google.golang.org/ - for the golang appengine package
your/project/path/src/golang.org/ - golang packages
your/project/path/src/github.org/ - github packages
The subfolders/package folders, must not be above the main app.yaml file. Furthermore, the golang appengine package must be placed right inside "src/" and can only be imported directly from the "google.golang.org" import path and below that, not above. i.e. "customFolder/google.golang.org" is not allowed, "appengine", is however, allowed, provided that the app.yaml file is directly under src folder : src/app.yaml - src/mainapp.go.