I was trying to deploy an API using PubSub with AppEngine but I got a "not an App Engine context" error, it's related to the following code:
import (
"golang.org/x/net/context"
"log"
"cloud.google.com/go/pubsub"
)
var (
ctx context.Context
pubsubClient *pubsub.Client
)
func InitPubSub () {
ctx = context.Background()
psClient, err := pubsub.NewClient(ctx, "myproject-1234")
if err != nil {
log.Println("(init pub sub) error while creating new pubsub client:", err)
} else {
pubsubClient = psClient
}
}
So I was looking at the BackgroundContext func from the appengine package but it says that it only works with AppEngine flexible environment (standard environment seems more appropriate to my app): https://godoc.org/google.golang.org/appengine#BackgroundContext
Do you know if there's another function I can use? Or should I create and close a client for each request?
Thanks!