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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 /*
nodir 2016/06/13 20:20:52 I think we use // everywhere
nishanths 2016/06/15 18:25:08 Done.
6 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.
7 It wraps around julienschmidt/httprouter.
8
9 Usage:
10
11 r := router.New()
12 r.Use(Logger())
13 r.GET("/", RootSpecificMiddleware(), rootHandler) // Executes Logger, Ro otSpecificMiddleware, rootHandler in order
14
15 authorized := r.Group("authorized")
16 authorized.Use(Authenticator(), SecondAuthMiddleware())
17 authorized.DELETE("/comment/:id", commentDeleteHandler) // Executes Logg er, Authenticator, SecondAuthMiddleware, commentDeleteHandler in order (path: /a uthorized/comment/:id)
18
19 func rootHandler(c *router.Context) {
20 io.WriteString(c.Writer, "hello from the root route")
21 }
22
23 func Logger() router.Handler {
24 return func(c *router.Context) {
25 log.Println("log before")
26 c.Context = context.WithValue(c.Context, "foo", "bar")
27 c.Next()
28 log.Println("log after")
29 }
30 }
31 */
32 package router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698