appengine
                                
                                 appengine copied to clipboard
                                
                                    appengine copied to clipboard
                            
                            
                            
                        all: better error message for "not an App Engine context"
Especially for Go 1.11, where appengine.Main isn't required, it's confusing when people try to use this package without appengine.Main.
Maybe we should modify the message to point to a doc explaining how to resolve the error, especially as it'll be much more common to see in Go 1.11+.
/cc @sbuss
@broady: I come here since I'm victim to the same error.
How would one implement this correctly?
I am currently using julienschmidt's httprouter, so none of my handlers are having any effect with appengine.Main().
func main() {
	logger.Init(os.Stdout, os.Stdout, os.Stderr, os.Stderr)
	config, err := system.LoadConfig()
	if err != nil {
		logger.Error.Printf("Could not load config: %v", err)
	}
	listenAddr := fmt.Sprintf("%s:%d", config.ListeningHost, config.ListeningPort)
	err, router := system.NewRouter(listenAddr) // httprouter
	if err != nil {
		logger.Error.Printf("could not create router: %v", err)
	}
	defer router.Close()
	router.SetPanicHandler(handlers.PanicHandler())
	db, err := system.GetDBInstance(
		config.ProjectID,
		config.DBInstance,
		config.DBName,
		config.DBUser,
		config.DBPassword,
	)
	if err != nil {
		logger.Error.Printf("could not connect to DB: %v", err)
	}
	defer db.Close()
	migrateDB(db)
	setupRoutes(router, db)
	language.Init()
	logger.Info.Println("Started listening on " + listenAddr)
	logger.Info.Println(router.Listen())
}
@broady Perhaps until this can be fixed properly, you (or someone) can roughly explain what this error means and how to handle it?
I just ran into this trying to use Go 1.11 on App Engine Standard, and I'm at a bit of a loss to understand it or how to proceed.
Update: It looks like the issue is that if you want to use the old google.golang.org/appengine/* APIs, then you have to use appengine.Main(). (In retrospect, this now seems obvious from @broady's original comment; but it wasn't when I was first digging into the issue.)
Exactly right, @mdempsky.
That said, with the second generation beta runtime (go1.11), I believe it's technically possible to construct a valid App Engine context with just an *http.Request, without requiring use of appengine.Main.
I believe it's technically possible to construct a valid App Engine context with just an *http.Request, without requiring use of appengine.Main.
I'm not sure if by technically possible you're referring to it's possible for (1) app developers to today use the classic client libraries without using appengine.Main, or that it's possible that (2) the classic client libraries could be modified to work without appengine.Main.
I don't think 1 is true. The only non-test function that creates an internal.context value appears to be internal.handleHTTP, which is only used by internal.Main (in turn used by appengine.Main).
I do think 2 is likely true though.
@broady I'm using 1.12 and getting this error so it seems that using appengine.Main is necessary.
Yes, you must use appengine.Main if you want to use the packages under google.golang.org/appengine.
You don't have to use those packages, though.
On Thu, Jul 18, 2019, 3:28 PM emirhosseini [email protected] wrote:
@broady https://github.com/broady I'm using 1.12 and getting this error so it seems that using appengine.Main is necessary.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/golang/appengine/issues/172?email_source=notifications&email_token=AAAGDFXNHUSK2SZRGEOLIRLQADVBPA5CNFSM4GB5RB4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2J7JCQ#issuecomment-513012874, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAGDFSNB35UBAGQWMZXUSLQADVBPANCNFSM4GB5RB4A .