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

Unified Diff: server/router/doc.go

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: router: Do not allocate merged array in Handle Created 4 years, 6 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 | « no previous file | server/router/handler.go » ('j') | server/router/handler.go » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: server/router/doc.go
diff --git a/server/router/doc.go b/server/router/doc.go
new file mode 100644
index 0000000000000000000000000000000000000000..e6be0012f374e52d6b7e03a44afa9f6d5aa3122c
--- /dev/null
+++ b/server/router/doc.go
@@ -0,0 +1,31 @@
+// Copyright 2016 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+// Package router provides an HTTP router with support for middleware and groups.
+// It wraps around julienschmidt/httprouter.
+//
+// Usage:
+//
+// r := router.New()
+// r.Use(MiddlewareChain{Logger()})
+// r.GET("/", MiddlewareChain{Foo()}, rootHandler) // Executes Logger, Foo, rootHandler in order
+//
+// authorized := r.Group("authorized")
+// authorized.Use(MiddlewareChain{Authenticator(), Bar()})
+// authorized.DELETE("/comment/:id", nil, delHandler) // Executes Logger, Authenticator, Bar, delHandler in order (path: /authorized/comment/:id)
+//
+// func rootHandler(c *router.Context) {
+// io.WriteString(c, "hello from the root route")
+// }
+//
+// func Logger() router.Middleware {
+// return func(c *router.Context, next router.Handler) {
+// print("log before")
+// c.Context = context.WithValue(c.Context, "x", "y")
+// next(c)
+// print("log after")
+// }
+// }
+//
nodir 2016/06/15 20:14:43 it may be (or may be not) better to move this exam
nishanths 2016/06/16 00:14:18 Moved to example_test.go and removed this file. Co
+package router
« no previous file with comments | « no previous file | server/router/handler.go » ('j') | server/router/handler.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698