Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2221)

Unified Diff: appengine/middleware/doc.go

Issue 1402543003: Add initial middleware package. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: nits Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/middleware/context.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/middleware/doc.go
diff --git a/appengine/middleware/doc.go b/appengine/middleware/doc.go
new file mode 100644
index 0000000000000000000000000000000000000000..c57e39953921895ac309f09d681987784fc81bf1
--- /dev/null
+++ b/appengine/middleware/doc.go
@@ -0,0 +1,48 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Package middleware provides a standard set of middleware tools for luci
+// appengine apps. It's built around "github.com/julienschmidt/httprouter".
+//
+// Usage Example
+//
+// Middleware is pretty basic to use. You pick one of the 'Base' functions,
+// then layer middlewares, making the innermost middleware your actual handler
+// function.
+//
+// BaseProd and BaseTest ensure that the context has a full compliment of
+// luci/gae services, as well as a luci-go/common/logging service.
+//
+// import (
+// "log"
+//
+// "github.com/julienschmidt/httprouter"
+// "github.com/luci/gae/service/datastore"
+// "github.com/luci/luci-go/appengine/middleware"
+// "github.com/luci/luci-go/common/logging"
+// )
+//
+// // Thing is just a silly datastore model for the example.
+// type Thing struct{
+// ID string `gae:"$id"`
+// }
+//
+// func myHandler(c context.Context, rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
+// if err := datastore.Get(c).Put(&Thing{ID: p.ByName("thing_id")}); err != nil {
+// logging.Errorf(c, "failed to put thing: %s", err)
+// fmt.Fprintf("error: %s", err)
+// rw.WriteHeader(500)
+// return
+// }
+// rw.Write([]byte("ok"))
+// }
+//
+// func init() {
+// router := httprouter.New()
+// router.GET("/internal/make_thing/:obj_id",
+// middleware.BaseProd(middleware.RequireCron(myHandler)))
+//
+// log.Fatal(http.ListenAndServe(":8080", router))
+// }
+package middleware
« no previous file with comments | « appengine/middleware/context.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698