nbio/hitch

How would you use this with google app engine?

Closed this issue · 4 comments

I'm wanting to use this with gae, but I can't seem to figure it out.

Most go frameworks I've tried work fine on app engine, the normal approach is to use init instead of main and map the mux / router to the default http.handler instead of calling ListenAndServe (the app engine adds it's own main wrapper I believe):

So, instead of:

func main() {
    h := hitch.New()
    h.Get("/", http.HandlerFunc(Home))
    http.ListenAndServe(":8000", h.handler())
}

You'd have something like:

func init() {
    h := hitch.New()
    h.Get("/", http.HandlerFunc(Home))
    http.Handle("/", h.handler())
}

It's fairly easy to have some compiler tags so the same app can be run on app engine or on a regular server (Obviously, you need to put any services behind an interface so you can swap out any app engine specific components)

We haven't tried using hitch on GAE, so it is untested there. We'd be pleased to review a PR with any necessary changes.

Separately, we were tossing around the idea of switching to https://github.com/labstack/echo, but switching HTTP routers is not a high priority for us right now.

Okay. I'm stilling learning some of the http interfacing, but from what I could tell, I was making the foolish mistake of calling http.Handle("/", h), instead of http.Handle("/", h.handler()).

Thanks!

Glad you're unblocked! If there was something in the docs that confused you, please let us know. We would like to fix it.