Exemple #1
0
func init() {
	m := pat.New()
	m.Post("/signups", appstats.NewHandler(createSignUpAsync))
	m.Post("/signups/task", appstats.NewHandler(createSignUp))
	m.Get("/sendemail", appstats.NewHandler(sendEmail))
	m.Get("/", appstats.NewHandler(newSignUp))
	http.Handle("/", m)
}
Exemple #2
0
func appstatsWrapper(h Handler) http.Handler {
	f := func(c appengine.Context, w http.ResponseWriter, req *http.Request) {
		// Emit some compatibility & anti-cache headers for IE (you can overwrite
		// them from the handlers)
		w.Header().Set("X-UA-Compatible", "chrome=1")
		w.Header().Set("Cache-Control", "max-age=0,no-cache,no-store,"+
			"post-check=0,pre-check=0")
		w.Header().Set("Expires", "Mon, 26 Jul 1997 05:00:00 GMT")

		// Build the request & session objects
		rw := newResponseWriter(w)
		r := &Request{Req: req, W: rw, C: c, N: goon.FromContext(c)}

		session, token, err := getSession(req, rw)
		if err != nil {
			r.processError(fmt.Errorf("build session failed: %s", err))
			return
		}
		r.Session = session

		// Check XSRF token
		if req.Method != "GET" {
			if ok, err := checkXsrfToken(req, token); err != nil {
				r.processError(fmt.Errorf("check xsrf token failed: %s", err))
				return
			} else if !ok {
				c.Errorf("xsrf token header check failed")
				r.processError(Forbidden())
				return
			}
		}

		// Fatal errors recovery
		defer func() {
			if rec := recover(); rec != nil {
				err := fmt.Errorf("panic recovered error: %s", rec)
				r.processError(err)
			}
		}()

		// Handle the request
		if err := h(r); err != nil {
			r.processError(err)
		}

		// Save the session & copy the buffered output
		if err := sessions.Save(req, w); err != nil {
			r.processError(err)
		}
		if err := rw.output(); err != nil {
			r.processError(err)
		}
	}
	return appstats.NewHandler(f)
}
Exemple #3
0
func init() {
	http.Handle("/print", appstats.NewHandler(blobList))
	http.Handle("/blob2", appstats.NewHandler(blobList))
	http.Handle("/blob2/upload", appstats.NewHandler(submitUpload))
	http.Handle("/blob2/processing-new-upload", appstats.NewHandler(processUpload))
	http.Handle("/blob2/serve-full", appstats.NewHandler(serveFull))
	http.Handle("/blob2/thumb", appstats.NewHandler(serveThumb))
	http.Handle("/blob2/rename-delete", appstats.NewHandler(renameOrDelete))
}
Exemple #4
0
func CreateHandler(handlerFunc func(appengine.Context, http.ResponseWriter, *http.Request)) appstats.Handler {
	return appstats.NewHandler(func(c appengine.Context, w http.ResponseWriter, r *http.Request) {
		headers := w.Header()
		headers.Set("X-Frame-Options", "SAMEORIGIN")
		headers.Set("X-XSS-Protection", "0")

		c.Infof("Request ID: %s", appengine.RequestID(c))

		handlerFunc(c, w, r)
	})
}
Exemple #5
0
//Handler maps standard net/http handlers to handlers accepting Context
func Handler(hand func(Context) error) http.Handler {
	return appstats.NewHandler(func(c appengine.Context, w http.ResponseWriter, r *http.Request) {
		vars := mux.Vars(r)
		context := Context{Context: c, W: w, R: r, Vars: vars}
		err := hand(context)
		if err != nil {
			c.Errorf("Error 500. %v", err)
			w.WriteHeader(http.StatusInternalServerError)
			RenderLayout("error.html", "Chyba", err, context)
		}
	})
}
Exemple #6
0
func init() {
	http.Handle("/submit/map", appstats.NewHandler(submitMap))
	http.Handle("/submit/bulkUpdateUnique", appstats.NewHandler(submitBulkUpdateUnique))

	http.Handle("/batch/map", appstats.NewHandler(batchMap))
	http.Handle("/batch/couch", appstats.NewHandler(batchCouch))
	http.Handle("/batch/updateUnique", appstats.NewHandler(batchPrepareUnique))
	http.Handle("/batch/bulkUpdateUnique", appstats.NewHandler(batchBulkUpdateUnique))
	http.Handle("/batch/destroy", appstats.NewHandler(batchDestroy))
}
Exemple #7
0
// NewHandler returns a profiled, appstats-aware appengine.Context.
func NewHandler(f func(Context, http.ResponseWriter, *http.Request)) http.Handler {
	return appstats.NewHandler(func(c appengine.Context, w http.ResponseWriter, r *http.Request) {
		h := miniprofiler.NewHandler(func(t miniprofiler.Timer, w http.ResponseWriter, r *http.Request) {
			pc := Context{
				Context: c.(appstats.Context),
				Timer:   t,
			}
			t.SetName(miniprofiler.FuncName(f))
			f(pc, w, r)
			t.AddCustomLink("appstats", pc.URL())
		})
		h.ServeHTTP(w, r)
	})
}
// NewHandler returns a profiled, appstats-aware appengine.Context.
func NewHandler(f func(Context, http.ResponseWriter, *http.Request)) appstats.Handler {
	return appstats.NewHandler(func(c appengine.Context, w http.ResponseWriter, r *http.Request) {
		pc := Context{
			Context: c.(appstats.Context),
		}
		pc.P = miniprofiler.NewProfile(w, r, miniprofiler.FuncName(f))
		f(pc, w, r)

		if pc.P.Root != nil {
			pc.P.CustomLink = pc.URL()
			pc.P.CustomLinkName = "appstats"
			pc.P.Finalize()
		}
	})
}
Exemple #9
0
// NewHandler returns a profiled, appstats-aware appengine.Context.
func NewHandler(f func(Context, http.ResponseWriter, *http.Request)) appstats.Handler {
	return appstats.NewHandler(func(c appengine.Context, w http.ResponseWriter, r *http.Request) {
		h := miniprofiler.NewHandler(func(p *miniprofiler.Profile, w http.ResponseWriter, r *http.Request) {
			pc := Context{
				Context: c.(appstats.Context),
				Profile: p,
			}
			p.Name = miniprofiler.FuncName(f)
			f(pc, w, r)

			if pc.Profile.Root != nil {
				pc.Profile.CustomLink = pc.URL()
				pc.Profile.CustomLinkName = "appstats"
			}
		})
		h.ServeHTTP(w, r)
	})
}
Exemple #10
0
func init() {
	http.Handle("/users", appstats.NewHandler(users))
}
Exemple #11
0
func init() {
	http.Handle("/api/update-account", appstats.NewHandler(handleUpdateAccount))

	http.Handle("/api/new-cellar", appstats.NewHandler(handleNewCellarRequest))
	http.Handle("/api/delete-cellar", appstats.NewHandler(handleDeleteCellarRequest))
	http.Handle("/api/update-cellar", appstats.NewHandler(handleUpdateCellarRequest))

	http.Handle("/api/new-beer", appstats.NewHandler(handleNewBeerRequest))
	http.Handle("/api/delete-beer", appstats.NewHandler(handleDeleteBeerRequest))
	http.Handle("/api/transfer-beer", appstats.NewHandler(handleTransferBeerRequest))
	http.Handle("/api/update-beer", appstats.NewHandler(handleUpdateBeerRequest))

	http.Handle("/api/new-tasting", appstats.NewHandler(handleNewTastingRequest))
	http.Handle("/api/delete-tasting", appstats.NewHandler(handleDeleteTastingRequest))
	http.Handle("/api/update-tasting", appstats.NewHandler(handleUpdateTastingRequest))

	http.Handle("/api/get-qr-code", appstats.NewHandler(handleQRCodeRequest))
}
Exemple #12
0
func init() {
	http.Handle("/mycellars", appstats.NewHandler(mycellars))
}
Exemple #13
0
func init() {
	http.Handle("/cellar", appstats.NewHandler(cellar))
}
Exemple #14
0
func init() {
	http.HandleFunc("/", front)
	http.Handle("/checkout", appstats.NewHandler(checkout))
	http.HandleFunc("/admin/populate", adminPopulate)
}
func init() {
	http.Handle("/updateUnique", appstats.NewHandler(processUpdateUnique))
}
Exemple #16
0
func init() {
	http.Handle("/", appstats.NewHandler(index))
}
Exemple #17
0
func init() {
	http.Handle("/couchit", appstats.NewHandler(postToCouch))
	http.Handle("/resend", appstats.NewHandler(resendItem))
}
Exemple #18
0
func init() {
	http.Handle("/myaccount", appstats.NewHandler(myaccount))
	http.Handle("/export", appstats.NewHandler(exportaccount))
	http.Handle("/import", appstats.NewHandler(importaccount))
}
Exemple #19
0
func init() {
	http.Handle("/p_crawl", appstats.NewHandler(pcrawlHandler))
}
Exemple #20
0
func init() {
	http.Handle("/", appstats.NewHandler(HomeHandler))
}
Exemple #21
0
func NewAppHandler(f func(appengine.Context, http.ResponseWriter, *http.Request)) AppHandler {
	return AppHandler{
		f: appstats.NewHandler(f),
	}
}
Exemple #22
0
func init() {
	http.Handle("/v2", appstats.NewHandler(handleV2))
}
Exemple #23
0
func init() {
	http.Handle("/tasting", appstats.NewHandler(tasting))
}
Exemple #24
0
func init() {
	http.Handle("/email", appstats.NewHandler(storeEmail))
}
Exemple #25
0
func init() {
	http.Handle("/asyncStoreStats", appstats.NewHandler(doAsyncStoreStats))
	http.Handle("/asyncStoreEmail", appstats.NewHandler(doAsyncStoreEmail))
	http.Handle("/asyncRollupRecent", appstats.NewHandler(doAsyncRollupRecent))
}
func init() {
	http.Handle("/blob2/form-redirector", appstats.NewHandler(formRedirector))
}
Exemple #27
0
func init() {
	http.Handle("/beer", appstats.NewHandler(beer))
	http.Handle("/universal-beer", appstats.NewHandler(universalbeer))
}
Exemple #28
0
func init() {
	Router.Get("/_ah/cron/search", appstats.NewHandler(ahCronSearchHandler))
	Router.Get("/_ah/status", appstats.NewHandler(ahStatusHandler))
	Router.Get("/_ah/", appstats.NewHandler(ahHandler))

	Router.Get("/debug/prepare_test", appstats.NewHandler(debugPrepareTestHandler))

	Router.Get("/-/about", appstats.NewHandler(aboutHandler))
	Router.Get("/-/doc", appstats.NewHandler(docHandler))
	Router.Get("/-/doc/:section", appstats.NewHandler(docHandler))
	Router.Get("/-/me", appstats.NewHandler(myHandler))
	Router.Post("/-/me/register", appstats.NewHandler(registerHandler))
	Router.Get("/-/me/generate", appstats.NewHandler(generateHandler))
	Router.Post("/-/me/openid", appstats.NewHandler(openIdHandler))
	Router.Get("/-/nuts", appstats.NewHandler(nutsHandler))

	Router.Put("/:vendor/:name/:version", appstats.NewHandler(nutCreateHandler))
	Router.Get("/:vendor/:name/:version", appstats.NewHandler(nutShowHandler))
	Router.Get("/:vendor/:name", appstats.NewHandler(nutShowHandler))
	Router.Get("/:vendor", appstats.NewHandler(nutsHandler))

	Router.Get("/", appstats.NewHandler(welcomeHandler))

	http.Handle("/", Router)

	Base = template.Must(template.ParseFiles("gonuts/templates/base.html"))
	template.Must(Base.ParseGlob("gonuts/templates/base/*.html"))
}
Exemple #29
0
func init() {
	http.Handle("/stats", appstats.NewHandler(storeStatsV1))
}