Chromium Code Reviews| 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 |