本文整理匯總了Golang中github.com/mjibson/appstats.NewHandler函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewHandler函數的具體用法?Golang NewHandler怎麽用?Golang NewHandler使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewHandler函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: init
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)
}
示例2: appstatsWrapper
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)
}
示例3: init
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))
}
示例4: CreateHandler
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)
})
}
示例5: Handler
//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)
}
})
}
示例6: init
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))
}
示例7: NewHandler
// 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)
})
}
示例8: NewHandler
// 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()
}
})
}
示例9: NewHandler
// 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)
})
}
示例10: init
func init() {
http.Handle("/users", appstats.NewHandler(users))
}
示例11: init
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))
}
示例12: init
func init() {
http.Handle("/mycellars", appstats.NewHandler(mycellars))
}
示例13: init
func init() {
http.Handle("/cellar", appstats.NewHandler(cellar))
}
示例14: init
func init() {
http.HandleFunc("/", front)
http.Handle("/checkout", appstats.NewHandler(checkout))
http.HandleFunc("/admin/populate", adminPopulate)
}
示例15: init
func init() {
http.Handle("/updateUnique", appstats.NewHandler(processUpdateUnique))
}