I am evaluating appengine for a golang project. It is a simple REST server with a bunch of endpoints. I am currently deploying it in AWS, in an EC2 instance. I have written a systemd script file which will take care of launching the webserver as a systemd service (so that it is always up etc.).
I am evaluating appengine and I see that we need to change the package main to something else, as appengine needs to have its own main package. This is kind of annoying as now I cannot easily test in my dev laptop or have the same code across my EC2 instance and appengine. So, are there any tricks to switch the main package automatically when I am deploying to appengine ? (Some kind of pre-push patch or something ?)
评论:
broady:
psankar:You can use a main package.
package main import ( "net/http" "google.golang.org/appengine" ) func main() { http.HandleFunc(...) appengine.Main() }
broady:This is brilliant. Thanks. I never knew that appengine can live without a Main package. This is not covered even in the official go-appengine docs. I posted this query in the golang nuts list also. https://groups.google.com/forum/#!topic/golang-nuts/Vce6234vk8E I believe that it will be nice if you could reply there also, so that it will be beneficial to many. If you want, I could just refer to this thread and send the mail myself too. Thanks.
nstratos:Done. Yes, sorry, updating docs is on a list of things to do. Thank you!
psankar:Use build tags on top of your main files like:
// +build appengine
and
// +build !appengine
Check golang/perf out.
Thanks. But, I think I will go with the appengine.Main function recommended in the other comment.
