Skip to content

Instantly share code, notes, and snippets.

@K3TH3R
Created January 1, 2016 23:36
Show Gist options
  • Save K3TH3R/1748fe105954f3eaa32e to your computer and use it in GitHub Desktop.
Save K3TH3R/1748fe105954f3eaa32e to your computer and use it in GitHub Desktop.
Golang App Engine - Using Echo router with Appstats (for fixing/optimizing queries)
// +build appengine
package main
import (
"github.com/labstack/echo"
"github.com/mjibson/appstats"
"golang.org/x/net/context"
"net/http"
)
// reference our echo instance and create it early
var e = createMux()
func init() {
// note: we don't need to provide the middleware or static handlers,
// that's taken care of by the platform
// app engine has it's own "main" wrapper - we just need to hook
// appstats and echo into the default handler
http.Handle("/", appstats.NewHandler(echoServe))
}
func echoServe(c context.Context, w http.ResponseWriter, r *http.Request) {
e.ServeHTTP(w, r)
}
func createMux() *echo.Echo {
e := echo.New()
e.Favicon("assets/images/favicon.png")
e.Static("/assets", "assets")
return e
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment