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

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: Update tests 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
Index: server/router/doc.go
diff --git a/server/router/doc.go b/server/router/doc.go
new file mode 100644
index 0000000000000000000000000000000000000000..00650351dfcf3dfd1292e7cb6aaedf3c5c096b65
--- /dev/null
+++ b/server/router/doc.go
@@ -0,0 +1,32 @@
+// 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.
+
+/*
nodir 2016/06/13 20:20:52 I think we use // everywhere
nishanths 2016/06/15 18:25:08 Done.
+Package router provides a HTTP router with support for middleware and groups.
nodir 2016/06/13 20:20:52 s/a HTTP/an HTTP/
nishanths 2016/06/15 18:25:08 Done.
+It wraps around julienschmidt/httprouter.
+
+Usage:
+
+ r := router.New()
+ r.Use(Logger())
+ r.GET("/", RootSpecificMiddleware(), rootHandler) // Executes Logger, RootSpecificMiddleware, rootHandler in order
+
+ authorized := r.Group("authorized")
+ authorized.Use(Authenticator(), SecondAuthMiddleware())
+ authorized.DELETE("/comment/:id", commentDeleteHandler) // Executes Logger, Authenticator, SecondAuthMiddleware, commentDeleteHandler in order (path: /authorized/comment/:id)
+
+ func rootHandler(c *router.Context) {
+ io.WriteString(c.Writer, "hello from the root route")
+ }
+
+ func Logger() router.Handler {
+ return func(c *router.Context) {
+ log.Println("log before")
+ c.Context = context.WithValue(c.Context, "foo", "bar")
+ c.Next()
+ log.Println("log after")
+ }
+ }
+*/
+package router

Powered by Google App Engine
This is Rietveld 408576698