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 // Package router provides an HTTP router with support for middleware and groups . | |
| 6 // It wraps around julienschmidt/httprouter. | |
| 7 // | |
| 8 // Usage: | |
| 9 // | |
| 10 // r := router.New() | |
| 11 // r.Use(MiddlewareChain{Logger()}) | |
| 12 // r.GET("/", MiddlewareChain{Foo()}, rootHandler) // Executes Logger, Foo, rootHandler in order | |
| 13 // | |
| 14 // authorized := r.Group("authorized") | |
| 15 // authorized.Use(MiddlewareChain{Authenticator(), Bar()}) | |
| 16 // authorized.DELETE("/comment/:id", nil, delHandler) // Executes Logger, A uthenticator, Bar, delHandler in order (path: /authorized/comment/:id) | |
| 17 // | |
| 18 // func rootHandler(c *router.Context) { | |
| 19 // io.WriteString(c, "hello from the root route") | |
| 20 // } | |
| 21 // | |
| 22 // func Logger() router.Middleware { | |
| 23 // return func(c *router.Context, next router.Handler) { | |
| 24 // print("log before") | |
| 25 // c.Context = context.WithValue(c.Context, "x", "y") | |
| 26 // next(c) | |
| 27 // print("log after") | |
| 28 // } | |
| 29 // } | |
| 30 // | |
|
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
| |
| 31 package router | |
| OLD | NEW |