mirror of https://github.com/gin-gonic/gin.git
Merge pull request #362 from javierprovecho/fix-middlewares-typo
Fix #252 typo (middlewares -> middleware)
This commit is contained in:
commit
5f56db59be
16
README.md
16
README.md
|
@ -88,8 +88,8 @@ import "github.com/gin-gonic/gin"
|
|||
|
||||
```go
|
||||
func main() {
|
||||
// Creates a gin router with default middlewares:
|
||||
// logger and recovery (crash-free) middlewares
|
||||
// Creates a gin router with default middleware:
|
||||
// logger and recovery (crash-free) middleware
|
||||
router := gin.Default()
|
||||
|
||||
router.GET("/someGet", getting)
|
||||
|
@ -192,7 +192,7 @@ func main() {
|
|||
```
|
||||
|
||||
|
||||
#### Blank Gin without middlewares by default
|
||||
#### Blank Gin without middleware by default
|
||||
|
||||
Use
|
||||
|
||||
|
@ -206,24 +206,24 @@ r := gin.Default()
|
|||
```
|
||||
|
||||
|
||||
#### Using middlewares
|
||||
#### Using middleware
|
||||
```go
|
||||
func main() {
|
||||
// Creates a router without any middleware by default
|
||||
r := gin.New()
|
||||
|
||||
// Global middlewares
|
||||
// Global middleware
|
||||
r.Use(gin.Logger())
|
||||
r.Use(gin.Recovery())
|
||||
|
||||
// Per route middlewares, you can add as many as you desire.
|
||||
// Per route middleware, you can add as many as you desire.
|
||||
r.GET("/benchmark", MyBenchLogger(), benchEndpoint)
|
||||
|
||||
// Authorization group
|
||||
// authorized := r.Group("/", AuthRequired())
|
||||
// exactly the same than:
|
||||
authorized := r.Group("/")
|
||||
// per group middlewares! in this case we use the custom created
|
||||
// per group middleware! in this case we use the custom created
|
||||
// AuthRequired() middleware just in the "authorized" group.
|
||||
authorized.Use(AuthRequired())
|
||||
{
|
||||
|
@ -439,7 +439,7 @@ r.GET("/test", func(c *gin.Context) {
|
|||
Both internal and external locations are supported.
|
||||
|
||||
|
||||
#### Custom Middlewares
|
||||
#### Custom Middleware
|
||||
|
||||
```go
|
||||
func Logger() gin.HandlerFunc {
|
||||
|
|
|
@ -76,7 +76,7 @@ func (c *Context) Copy() *Context {
|
|||
/*********** FLOW CONTROL ***********/
|
||||
/************************************/
|
||||
|
||||
// Next should be used only in the middlewares.
|
||||
// Next should be used only inside middleware.
|
||||
// It executes the pending handlers in the chain inside the calling handler.
|
||||
// See example in github.
|
||||
func (c *Context) Next() {
|
||||
|
|
8
gin.go
8
gin.go
|
@ -23,7 +23,7 @@ type (
|
|||
HandlerFunc func(*Context)
|
||||
HandlersChain []HandlerFunc
|
||||
|
||||
// Represents the web framework, it wraps the blazing fast httprouter multiplexer and a list of global middlewares.
|
||||
// Represents the web framework, it wraps the blazing fast httprouter multiplexer and a list of global middleware.
|
||||
Engine struct {
|
||||
RouterGroup
|
||||
HTMLRender render.HTMLRender
|
||||
|
@ -139,11 +139,11 @@ func (engine *Engine) NoMethod(handlers ...HandlerFunc) {
|
|||
engine.rebuild405Handlers()
|
||||
}
|
||||
|
||||
// Attachs a global middleware to the router. ie. the middlewares attached though Use() will be
|
||||
// Attachs a global middleware to the router. ie. the middleware attached though Use() will be
|
||||
// included in the handlers chain for every single request. Even 404, 405, static files...
|
||||
// For example, this is the right place for a logger or error management middleware.
|
||||
func (engine *Engine) Use(middlewares ...HandlerFunc) routesInterface {
|
||||
engine.RouterGroup.Use(middlewares...)
|
||||
func (engine *Engine) Use(middleware ...HandlerFunc) routesInterface {
|
||||
engine.RouterGroup.Use(middleware...)
|
||||
engine.rebuild404Handlers()
|
||||
engine.rebuild405Handlers()
|
||||
return engine
|
||||
|
|
|
@ -199,7 +199,7 @@ func TestMiddlewareAbortHandlersChainAndNext(t *testing.T) {
|
|||
assert.Equal(t, signature, "ACB")
|
||||
}
|
||||
|
||||
// TestFailHandlersChain - ensure that Fail interrupt used middlewares in fifo order as
|
||||
// TestFailHandlersChain - ensure that Fail interrupt used middleware in fifo order as
|
||||
// as well as Abort
|
||||
func TestMiddlewareFailHandlersChain(t *testing.T) {
|
||||
// SETUP
|
||||
|
|
|
@ -30,7 +30,7 @@ type routesInterface interface {
|
|||
}
|
||||
|
||||
// Used internally to configure router, a RouterGroup is associated with a prefix
|
||||
// and an array of handlers (middlewares)
|
||||
// and an array of handlers (middleware)
|
||||
type RouterGroup struct {
|
||||
Handlers HandlersChain
|
||||
BasePath string
|
||||
|
@ -38,9 +38,9 @@ type RouterGroup struct {
|
|||
root bool
|
||||
}
|
||||
|
||||
// Adds middlewares to the group, see example code in github.
|
||||
func (group *RouterGroup) Use(middlewares ...HandlerFunc) routesInterface {
|
||||
group.Handlers = append(group.Handlers, middlewares...)
|
||||
// Adds middleware to the group, see example code in github.
|
||||
func (group *RouterGroup) Use(middleware ...HandlerFunc) routesInterface {
|
||||
group.Handlers = append(group.Handlers, middleware...)
|
||||
return group.returnObj()
|
||||
}
|
||||
|
||||
|
@ -54,8 +54,8 @@ func (group *RouterGroup) Group(relativePath string, handlers ...HandlerFunc) *R
|
|||
}
|
||||
}
|
||||
|
||||
// Handle registers a new request handle and middlewares with the given path and method.
|
||||
// The last handler should be the real handler, the other ones should be middlewares that can and should be shared among different routes.
|
||||
// Handle registers a new request handle and middleware with the given path and method.
|
||||
// The last handler should be the real handler, the other ones should be middleware that can and should be shared among different routes.
|
||||
// See the example code in github.
|
||||
//
|
||||
// For GET, POST, PUT, PATCH and DELETE requests the respective shortcut
|
||||
|
|
Loading…
Reference in New Issue