This is a question and not a bug. I have to rely on you core contributors and hope you have enough knowledge to understand the following:
My team want to migrate our existing go-swagger app (server generated from spec) to Google App Engine (GAE). I could not find any previous attempt of doing this on Google search.
Basically, GAE is intrusive, and builds your code as a package instead of an app, and expects standard http handlers to be registered in main.go init function. If you look quickly at https://cloud.google.com/appengine/docs/go/how-requests-are-handled section "Requests and HTTP" you will see a sample an brief explanation.
My question: do you know if a go-swagger app can be migrated/work this way? I'm asking because I suspect the HTTP middleware you are using probably does a lot of magic things, including some ListenAndServe or similar. Which, I believe, cannot work on GAE.
Any comment appreciated. If you think that could work, some clue of directions, things to change would help.
did you see this thread? https://github.com/go-swagger/go-swagger/issues/47
From go's perspective go-swagger doesn't do anything particularly nasty. We try to not import many packages and the ones that we do need to be in pure go. So I think that makes it possible to move to app engine. I have no experience with it though. Keep us posted!
Thanks for your reply.
Yes, I have seen, and I believe it's slightly different because they use a different approach: the op says he is just using swagger generate spec. Meaning he probably already has an app, using standard http handlers.
In our case, we use swagger generate server and therefore our app relies entirely on your http middleware and the generated code.
From my limited understanding, GAE asks you to register your handlers, and that's all. They have some magic to actually listen and serve, hence my question.
My current attempt resulted in a panic :-) I've sent an support ticket to Google, trying to explain the situation, and I am waiting for their feedback.
I will update this thread if I find anything.
I have some updates:
With some help from Google support and many attempts, I've managed to get the simple TODO example working.
Basically, the key point is to initialize the handlers from the middleware like this:
server.ConfigureFlags()
server.ConfigureAPI()
http.Handle("/", server.GetHandler())
and then remove any further generated code since we must not start listening.
In addition, for some reason I had to tweak the route/handler mapping (initCacheHandler) to explicitly use "/" instead of empty string. It's still unclear why I had to do this.
Finally, a 3rd party "easyjson" needs to be tweaked as well, as it's using restricted API (unsafe package).
After all of this, yes: you can get a go-swagger app working on App Engine.
I believe we can close the issue.
I have some updates:
With some help from Google support and many attempts, I've managed to get the simple TODO example working.
Basically, the key point is to initialize the handlers from the middleware like this:
server.ConfigureFlags()
server.ConfigureAPI()
http.Handle("/", server.GetHandler())and then remove any further generated code since we must not start listening.
In addition, for some reason I had to tweak the route/handler mapping (initCacheHandler) to explicitly use "/" instead of empty string. It's still unclear why I had to do this.
Finally, a 3rd party "easyjson" needs to be tweaked as well, as it's using restricted API (unsafe package).
After all of this, yes: you can get a go-swagger app working on App Engine.
Would you please mind elaborating it further. I have a small demo app e-food which I also trying to deploy.
Most helpful comment
I have some updates:
With some help from Google support and many attempts, I've managed to get the simple TODO example working.
Basically, the key point is to initialize the handlers from the middleware like this:
server.ConfigureFlags()
server.ConfigureAPI()
http.Handle("/", server.GetHandler())
and then remove any further generated code since we must not start listening.
In addition, for some reason I had to tweak the route/handler mapping (initCacheHandler) to explicitly use "/" instead of empty string. It's still unclear why I had to do this.
Finally, a 3rd party "easyjson" needs to be tweaked as well, as it's using restricted API (unsafe package).
After all of this, yes: you can get a go-swagger app working on App Engine.