You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-14Lines changed: 24 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ I initially created [lars](https://github.com/go-playground/lars), which I still
18
18
Key & Unique Features
19
19
--------------
20
20
-[x] It sticks to Go's native implimentations while providing helper functions for convenience
21
-
-[x]**Fast & Efficient** - pure uses a custom version of [httprouter](https://github.com/julienschmidt/httprouter) so incredibly fast and efficient.
21
+
-[x]**Fast & Efficient** - pure uses a custom version of [httprouter](https://github.com/julienschmidt/httprouter)'s radix tree, so incredibly fast and efficient.
22
22
23
23
Installation
24
24
-----------
@@ -56,6 +56,15 @@ func helloWorld(w http.ResponseWriter, r *http.Request) {
56
56
}
57
57
```
58
58
59
+
RequestVars
60
+
-----------
61
+
This is an interface that is used to pass request scoped variables and functions using `context.Context`.
62
+
It is implimented in this way because retrieving values from `context` isn't the fastest, and so using this
63
+
the router can store multiple pieces of information while reducing lookup time to a single stored `RequestVars`.
64
+
65
+
Currently only the URL/SEO params are stored on the `RequestVars` but if/when more is added they can merely be added
66
+
to the `RequestVars` and there will be no additional lookup time.
67
+
59
68
URL Params
60
69
----------
61
70
@@ -66,8 +75,9 @@ p := p.New()
66
75
l.Get("/user/:id", UserHandler)
67
76
68
77
// extract params like so
69
-
rv:= pure.ReqestVars(r) // done this way so only have to extract from context once
70
-
rv.Params().Get(paramname)
78
+
rv:= pure.ReqestVars(r) // done this way so only have to extract from context once, read above
79
+
params:= rv.Params() or params:= pure.ReqestVars(r).Params()
80
+
params.Get(paramname)
71
81
72
82
// serve css, js etc.. pure.RequestVars(r).Params().Get(pure.WildcardParam) will return the remaining path if
**Note:** Since this router has only explicit matches, you can not register static routes and parameters for the same path segment. For example you can not register the patterns /user/new and /user/:user for the same request method at the same time. The routing of different request methods is independent from each other. I was initially against this, and this router allowed it in a previous version, however it nearly cost me in a big app where the dynamic param value say :type actually could have matched another static route and that's just too dangerous, so it is no longer allowed.
89
+
**Note:** Since this router has only explicit matches, you can not register static routes and parameters for the same path segment. For example you can not register the patterns /user/new and /user/:user for the same request method at the same time. The routing of different request methods is independent from each other. I was initially against this, however it nearly cost me in a large web application where the dynamic param value say :type actually could have matched another static route and that's just too dangerous and so it is not allowed.
80
90
81
91
Groups
82
92
-----
83
93
```go
84
94
85
-
p.Use(LoggingAndRecovery)
95
+
p.Use(LoggingAndRecovery, Gzip...)
86
96
...
87
97
p.Post("/users/add", ...)
88
98
@@ -92,25 +102,25 @@ user.Get("", ...)
92
102
user.Post("", ...)
93
103
user.Delete("/delete", ...)
94
104
95
-
contactInfo:= user.Group("/contact-info/:ciid")
105
+
contactInfo:= user.Group("/contact-info/:cid")
96
106
contactinfo.Delete("/delete", ...)
97
107
98
108
// creates a group for others + inherits all middleware registered using p.Use() + adds
99
109
// OtherHandler to middleware
100
110
others:= p.Group("/others", OtherHandler)
101
111
102
112
// creates a group for admin WITH NO MIDDLEWARE... more can be added using admin.Use()
103
-
admin:= p.Group("/admin",nil)
113
+
admin:= p.Group("/admin",nil)
104
114
admin.Use(SomeAdminSecurityMiddleware)
105
115
...
106
116
```
107
117
108
118
Decoding Body
109
119
-------------
110
-
currently JSON, XML, FORM + Multipart Form's are support out of the box.
120
+
currently JSON, XML, FORM, Multipart Form and url.Values are support out of the box.
111
121
```go
112
122
// second argument denotes yes or no I would like URL query parameter fields
113
-
// to be included. i.e. 'id' in route '/user?id=val' should it be included.
123
+
// to be included. i.e. 'id' and 'id2' in route '/user/:id?id2=val' should it be included.
@@ -142,15 +152,13 @@ comply with the following rule(s):
142
152
143
153
* Are completely reusable by the community without modification
144
154
145
-
Other middleware will be listed under the examples/middleware/... folder for a quick copy/paste modify. as an example a logging or
146
-
recovery middleware are very application dependent and therefore will be listed under the examples/middleware/...
155
+
Other middleware will be listed under the examples/middleware/... folder for a quick copy/paste modify. As an example a LoddingAndRecovery middleware is very application dependent and therefore will be listed under the examples/middleware/...
147
156
148
157
Benchmarks
149
158
-----------
150
-
Run on MacBook Pro (Retina, 15-inch, Late 2013) 2.6 GHz Intel Core i7 16 GB 1600 MHz DDR3 using Go version go1.7.1 darwin/amd64
159
+
Run on MacBook Pro (Retina, 15-inch, Late 2013) 2.6 GHz Intel Core i7 16 GB 1600 MHz DDR3 using Go version go1.7.3 darwin/amd64
151
160
152
-
NOTICE: pure uses a custom version of [httprouter](https://github.com/julienschmidt/httprouter), benchmarks can be found [here](https://github.com/joeybloggs/go-http-routing-benchmark/tree/pure-and-lars)
153
-
the slowdown is with the use of the `context` package, as you can see when no params, and therefore no need to store anything in the context, it is faster than even lars.
161
+
NOTICE: pure uses a custom version of [httprouter](https://github.com/julienschmidt/httprouter)'s radix tree, benchmarks can be found [here](https://github.com/joeybloggs/go-http-routing-benchmark/tree/pure-and-lars) the slowdown is with the use of the `context` package, as you can see when no SEO params are defined, and therefore no need to store anything in the context, it is faster than even lars.
154
162
155
163
```go
156
164
go test -bench=. -benchmem=true
@@ -193,6 +201,8 @@ Why? because my time is spread pretty thin maintaining all of the libraries I ha
193
201
it is so freeing not to worry about it and will help me keep pouring out bigger and better
194
202
things for you the community.
195
203
204
+
I am open versioning with gopkg.in should anyone request it, but this should be stable going forward.
205
+
196
206
Licenses
197
207
--------
198
208
-[MIT License](https://raw.githubusercontent.com/go-playground/pure/master/LICENSE) (MIT), Copyright (c) 2016 Dean Karn
0 commit comments