From 7c0c427b2d7cd2eb8e44dec478f4a95999c2f2de Mon Sep 17 00:00:00 2001 From: Javier Provecho Fernandez Date: Fri, 3 Jul 2015 20:12:01 +0200 Subject: [PATCH] Fix #252 typo (middlewares -> middleware) --- README.md | 34 +++++++++++++++++----------------- context.go | 2 +- gin.go | 8 ++++---- middleware_test.go | 2 +- routergroup.go | 12 ++++++------ 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 67c9fa8..8d2e07f 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,14 @@ [![GoDoc](https://godoc.org/github.com/gin-gonic/gin?status.svg)](https://godoc.org/github.com/gin-gonic/gin) [![Join the chat at https://gitter.im/gin-gonic/gin](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/gin-gonic/gin?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -Gin is a web framework written in Golang. It features a martini-like API with much better performance, up to 40 times faster thanks to [httprouter](https://github.com/julienschmidt/httprouter). If you need performance and good productivity, you will love Gin. +Gin is a web framework written in Golang. It features a martini-like API with much better performance, up to 40 times faster thanks to [httprouter](https://github.com/julienschmidt/httprouter). If you need performance and good productivity, you will love Gin. ![Gin console logger](https://gin-gonic.github.io/gin/other/console.png) ``` $ cat test.go ``` -```go +```go package main import "github.com/gin-gonic/gin" @@ -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) @@ -110,7 +110,7 @@ func main() { ```go func main() { router := gin.Default() - + // This handler will match /user/john but will not match neither /user/ or /user router.GET("/user/:name", func(c *gin.Context) { name := c.Param("name") @@ -125,7 +125,7 @@ func main() { message := name + " is " + action c.String(http.StatusOK, message) }) - + router.Run(":8080") } ``` @@ -147,7 +147,7 @@ func main() { } ``` -### Multipart/Urlencoded Form +### Multipart/Urlencoded Form ```go func main() { @@ -156,7 +156,7 @@ func main() { router.POST("/form_post", func(c *gin.Context) { message := c.PostForm("message") nick := c.DefaultPostForm("nick", "anonymous") - + c.JSON(200, gin.H{ "status": "posted", "message": message, @@ -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()) { @@ -247,7 +247,7 @@ To bind a request body into a type, use model binding. We currently support bind Note that you need to set the corresponding binding tag on all fields you want to bind. For example, when binding from JSON, set `json:"fieldname"`. -When using the Bind-method, Gin tries to infer the binder depending on the Content-Type header. If you are sure what you are binding, you can use BindWith. +When using the Bind-method, Gin tries to infer the binder depending on the Content-Type header. If you are sure what you are binding, you can use BindWith. You can also specify that specific fields are required. If a field is decorated with `binding:"required"` and has a empty value when binding, the current request will fail with an error. @@ -261,7 +261,7 @@ type LoginJSON struct { // Binding from form values type LoginForm struct { User string `form:"user" binding:"required"` - Password string `form:"password" binding:"required"` + Password string `form:"password" binding:"required"` } func main() { @@ -297,7 +297,7 @@ func main() { ``` -###Multipart/Urlencoded binding +###Multipart/Urlencoded binding ```go package main @@ -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 { diff --git a/context.go b/context.go index f5f0de4..126130f 100644 --- a/context.go +++ b/context.go @@ -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() { diff --git a/gin.go b/gin.go index 8130b88..693c787 100644 --- a/gin.go +++ b/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 diff --git a/middleware_test.go b/middleware_test.go index 7876c7e..3a9d2c4 100644 --- a/middleware_test.go +++ b/middleware_test.go @@ -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 diff --git a/routergroup.go b/routergroup.go index 20122cb..90fbb40 100644 --- a/routergroup.go +++ b/routergroup.go @@ -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