Beispiel #1
0
func setAppEngineContext(next alice.ContextHandler) alice.ContextHandler {
	fn := func(empty appContext.Context, w http.ResponseWriter, r *http.Request) {
		// we hang on our empty parent context the appengine context for further middlewares
		newContext := appengine.WithContext(empty, r)
		next.ServeHTTPContext(newContext, w, r)
	}
	return alice.ContextHandlerFunc(fn)
}
Beispiel #2
0
func NewRecoverHandler(next alice.ContextHandler) alice.ContextHandler {
	fn := func(c context.Context, w http.ResponseWriter, r *http.Request) {
		defer func() {
			if err := recover(); err != nil {
				log.Printf("panic: %+v", err)
				http.Error(w, http.StatusText(500), 500)
			}
		}()
		next.ServeHTTPContext(c, w, r)
	}
	return alice.ContextHandlerFunc(fn)
}
Beispiel #3
0
func middleware(h alice.ContextHandler) alice.ContextHandler {
	return alice.ContextHandlerFunc(func(ctx appContext.Context, rw http.ResponseWriter, req *http.Request) {
		ctx = newContextWithRequestID(ctx, req)
		h.ServeHTTPContext(ctx, rw, req)
	})
}