Created
January 1, 2016 23:36
-
-
Save K3TH3R/1748fe105954f3eaa32e to your computer and use it in GitHub Desktop.
Golang App Engine - Using Echo router with Appstats (for fixing/optimizing queries)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// +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