Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
| OLD | NEW |