Skip to content

Commit c9a8702

Browse files
Dean KarnDean Karn
authored andcommitted
update README
1 parent edcbec2 commit c9a8702

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

README.md

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ I initially created [lars](https://github.com/go-playground/lars), which I still
1818
Key & Unique Features
1919
--------------
2020
- [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.
2222

2323
Installation
2424
-----------
@@ -56,6 +56,15 @@ func helloWorld(w http.ResponseWriter, r *http.Request) {
5656
}
5757
```
5858

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+
5968
URL Params
6069
----------
6170

@@ -66,8 +75,9 @@ p := p.New()
6675
l.Get("/user/:id", UserHandler)
6776

6877
// 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)
7181

7282
// serve css, js etc.. pure.RequestVars(r).Params().Get(pure.WildcardParam) will return the remaining path if
7383
// you need to use it in a custom handler...
@@ -76,13 +86,13 @@ l.Get("/static/*", http.FileServer(http.Dir("static/")))
7686
...
7787
```
7888

79-
**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.
8090

8191
Groups
8292
-----
8393
```go
8494

85-
p.Use(LoggingAndRecovery)
95+
p.Use(LoggingAndRecovery, Gzip...)
8696
...
8797
p.Post("/users/add", ...)
8898

@@ -92,25 +102,25 @@ user.Get("", ...)
92102
user.Post("", ...)
93103
user.Delete("/delete", ...)
94104

95-
contactInfo := user.Group("/contact-info/:ciid")
105+
contactInfo := user.Group("/contact-info/:cid")
96106
contactinfo.Delete("/delete", ...)
97107

98108
// creates a group for others + inherits all middleware registered using p.Use() + adds
99109
// OtherHandler to middleware
100110
others := p.Group("/others", OtherHandler)
101111

102112
// 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)
104114
admin.Use(SomeAdminSecurityMiddleware)
105115
...
106116
```
107117

108118
Decoding Body
109119
-------------
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.
111121
```go
112122
// 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.
114124
if err := pure.Decode(r, true, maxBytes, &user); err != nil {
115125
log.Println(err)
116126
}
@@ -142,15 +152,13 @@ comply with the following rule(s):
142152

143153
* Are completely reusable by the community without modification
144154

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/...
147156

148157
Benchmarks
149158
-----------
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
151160

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.
154162

155163
```go
156164
go test -bench=. -benchmem=true
@@ -193,6 +201,8 @@ Why? because my time is spread pretty thin maintaining all of the libraries I ha
193201
it is so freeing not to worry about it and will help me keep pouring out bigger and better
194202
things for you the community.
195203

204+
I am open versioning with gopkg.in should anyone request it, but this should be stable going forward.
205+
196206
Licenses
197207
--------
198208
- [MIT License](https://raw.githubusercontent.com/go-playground/pure/master/LICENSE) (MIT), Copyright (c) 2016 Dean Karn

0 commit comments

Comments
 (0)