Fix #252 typo (middlewares -> middleware)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Javier Provecho Fernandez · committed by Javier Provecho Fernandez · parent d6425f1 · Browse files · 5 files·+29 added−29 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+29 added−29 removed
- other:+29 added−29 removed
Provenance
- Commit
7c0c427- Tree
313734d- Author
Javier Provecho Fernandez <javiertitan@gmail.com>- Committer
Javier Provecho Fernandez <javiertitan@gmail.com>- Parent
d6425f1
5 files changed+29 added−29 removed
modified:context.go+1 added-1 removed
74 unmodified lines75 /************************************/76 /*********** FLOW CONTROL ***********/77 /************************************/78 79-// Next should be used only in the middlewares.79+// Next should be used only inside middleware.80 // It executes the pending handlers in the chain inside the calling handler.81 // See example in github.82 func (c *Context) Next() {83 c.index++390 unmodified linesmodified:gin.go+4 added-4 removed
21 unmodified lines22 type (23 HandlerFunc func(*Context)24 HandlersChain []HandlerFunc25 26- // Represents the web framework, it wraps the blazing fast httprouter multiplexer and a list of global middlewares.26+ // Represents the web framework, it wraps the blazing fast httprouter multiplexer and a list of global middleware.27 Engine struct {28 RouterGroup29 HTMLRender render.HTMLRender30 allNoRoute HandlersChain107 unmodified lines138 engine.noMethod = handlers139 engine.rebuild405Handlers()140 }141 142-// Attachs a global middleware to the router. ie. the middlewares attached though Use() will be142+// Attachs a global middleware to the router. ie. the middleware attached though Use() will be143 // included in the handlers chain for every single request. Even 404, 405, static files...144 // For example, this is the right place for a logger or error management middleware.145-func (engine *Engine) Use(middlewares ...HandlerFunc) routesInterface {146- engine.RouterGroup.Use(middlewares...)145+func (engine *Engine) Use(middleware ...HandlerFunc) routesInterface {146+ engine.RouterGroup.Use(middleware...)147 engine.rebuild404Handlers()148 engine.rebuild405Handlers()149 return engine150 }185 unmodified linesmodified:middleware_test.go+1 added-1 removed
197 unmodified lines198 assert.Equal(t, w.Code, 410)199 assert.Equal(t, signature, "ACB")200 }201 202-// TestFailHandlersChain - ensure that Fail interrupt used middlewares in fifo order as202+// TestFailHandlersChain - ensure that Fail interrupt used middleware in fifo order as203 // as well as Abort204 func TestMiddlewareFailHandlersChain(t *testing.T) {205 // SETUP206 signature := ""49 unmodified linesmodified:README.md+17 added-17 removed
1 #Gin Web Framework [](https://travis-ci.org/gin-gonic/gin) [](https://coveralls.io/r/gin-gonic/gin?branch=master) 2 3 [](https://godoc.org/github.com/gin-gonic/gin) [](https://gitter.im/gin-gonic/gin?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)4 5-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. 5+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.6 7 8 9 ```10 $ cat test.go11 ```12-```go 12+```go13 package main14 15 import "github.com/gin-gonic/gin"16 70 unmodified lines87 #### Using GET, POST, PUT, PATCH, DELETE and OPTIONS88 89 ```go90 func main() {91- // Creates a gin router with default middlewares:92- // logger and recovery (crash-free) middlewares91+ // Creates a gin router with default middleware:92+ // logger and recovery (crash-free) middleware93 router := gin.Default()94 95 router.GET("/someGet", getting)96 router.POST("/somePost", posting)12 unmodified lines109 110 ```go111 func main() {112 router := gin.Default()113- 113+114 // This handler will match /user/john but will not match neither /user/ or /user115 router.GET("/user/:name", func(c *gin.Context) {116 name := c.Param("name")117 c.String(http.StatusOK, "Hello %s", name)6 unmodified lines124 action := c.Param("action")125 message := name + " is " + action126 c.String(http.StatusOK, message)127 })128- 128+129 router.Run(":8080")130 }131 ```132 13 unmodified lines146 router.Run(":8080")147 }148 ```149 150-### Multipart/Urlencoded Form 150+### Multipart/Urlencoded Form151 152 ```go153 func main() {154 router := gin.Default()155 156 router.POST("/form_post", func(c *gin.Context) {157 message := c.PostForm("message")158 nick := c.DefaultPostForm("nick", "anonymous")159- 159+160 c.JSON(200, gin.H{161 "status": "posted",162 "message": message,163 })27 unmodified lines191 }192 ```193 194 195-#### Blank Gin without middlewares by default195+#### Blank Gin without middleware by default196 197 Use198 199 ```go5 unmodified lines205 r := gin.Default()206 ```207 208 209-#### Using middlewares209+#### Using middleware210 ```go211 func main() {212 // Creates a router without any middleware by default213 r := gin.New()214 215- // Global middlewares215+ // Global middleware216 r.Use(gin.Logger())217 r.Use(gin.Recovery())218 219- // Per route middlewares, you can add as many as you desire.219+ // Per route middleware, you can add as many as you desire.220 r.GET("/benchmark", MyBenchLogger(), benchEndpoint)221 222 // Authorization group223 // authorized := r.Group("/", AuthRequired())224 // exactly the same than:225 authorized := r.Group("/")226- // per group middlewares! in this case we use the custom created226+ // per group middleware! in this case we use the custom created227 // AuthRequired() middleware just in the "authorized" group.228 authorized.Use(AuthRequired())229 {230 authorized.POST("/login", loginEndpoint)15 unmodified lines246 To bind a request body into a type, use model binding. We currently support binding of JSON, XML and standard form values (foo=bar&boo=baz).247 248 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"`.249 250-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. 250+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.251 252 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.253 254 ```go5 unmodified lines260 261 // Binding from form values262 type LoginForm struct {263 User string `form:"user" binding:"required"`264- Password string `form:"password" binding:"required"` 264+ Password string `form:"password" binding:"required"`265 }266 267 func main() {268 r := gin.Default()27 unmodified lines296 }297 ```298 299 300-###Multipart/Urlencoded binding 300+###Multipart/Urlencoded binding301 ```go302 package main303 304 import (133 unmodified lines438 ```439 Both internal and external locations are supported.440 441 442-#### Custom Middlewares442+#### Custom Middleware443 444 ```go445 func Logger() gin.HandlerFunc {446 return func(c *gin.Context) {133 unmodified linesmodified:routergroup.go+6 added-6 removed
28 unmodified lines29 StaticFS(string, http.FileSystem) routesInterface30 }31 32 // Used internally to configure router, a RouterGroup is associated with a prefix33-// and an array of handlers (middlewares)33+// and an array of handlers (middleware)34 type RouterGroup struct {35 Handlers HandlersChain36 BasePath string37 engine *Engine38 root bool39 }40 41-// Adds middlewares to the group, see example code in github.42-func (group *RouterGroup) Use(middlewares ...HandlerFunc) routesInterface {43- group.Handlers = append(group.Handlers, middlewares...)41+// Adds middleware to the group, see example code in github.42+func (group *RouterGroup) Use(middleware ...HandlerFunc) routesInterface {43+ group.Handlers = append(group.Handlers, middleware...)44 return group.returnObj()45 }46 47 // Creates a new router group. You should add all the routes that have common middlwares or the same path prefix.5 unmodified lines53 engine: group.engine,54 }55 }56 57-// Handle registers a new request handle and middlewares with the given path and method.58-// The last handler should be the real handler, the other ones should be middlewares that can and should be shared among different routes.57+// Handle registers a new request handle and middleware with the given path and method.58+// The last handler should be the real handler, the other ones should be middleware that can and should be shared among different routes.59 // See the example code in github.60 //61 // For GET, POST, PUT, PATCH and DELETE requests the respective shortcut62 // functions can be used.136 unmodified lines