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 |