Skip to content

Commit 126c912

Browse files
author
Dean Karn
authored
Updated (#8)
- Updated to use Go Modules - Updated to use github.com/go-playground/pkg for HTTP abstractions. pure now also relies on the github.com/go-playground/pkg/net/http.DefaultFormDecoder; it is configurable.
1 parent 2edcbff commit 126c912

16 files changed

+210
-540
lines changed

.travis.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,11 @@ notifications:
1515
before_install:
1616
- go get -u github.com/go-playground/overalls
1717
- go get -u github.com/mattn/goveralls
18-
# - go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
19-
- go get -u github.com/client9/misspell/cmd/misspell
20-
21-
before_script:
22-
- go vet ./...
18+
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.16.0
2319

2420
script:
25-
- gofmt -d -s .
26-
# - golangci-lint run
27-
- find . -type f | xargs misspell -source=text
28-
- go test -cover -race ./...
21+
- make test
22+
- ./bin/golangci-lint run
2923

3024
after_success: |
3125
[ $TRAVIS_GO_VERSION = 1.12.5 ] &&

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
GOCMD=GO111MODULE=on go
2+
3+
linters-install:
4+
@golangci-lint --version >/dev/null 2>&1 || { \
5+
echo "installing linting tools..."; \
6+
$(GOCMD) get github.com/golangci/golangci-lint/cmd/golangci-lint; \
7+
}
8+
9+
lint: linters-install
10+
golangci-lint run
11+
12+
test:
13+
$(GOCMD) test -cover -race ./...
14+
15+
bench:
16+
$(GOCMD) test -bench=. -benchmem ./...
17+
18+
.PHONY: linters-install lint test bench

README.md

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package pure
22
============
3-
<img align="right" src="https://raw.githubusercontent.com/go-playground/pure/master/logo.png">![Project status](https://img.shields.io/badge/version-4.2.0-green.svg)
3+
<img align="right" src="https://raw.githubusercontent.com/go-playground/pure/master/logo.png">![Project status](https://img.shields.io/badge/version-5.0.0-green.svg)
44
[![Build Status](https://travis-ci.org/go-playground/pure.svg?branch=master)](https://travis-ci.org/go-playground/pure)
55
[![Coverage Status](https://coveralls.io/repos/github/go-playground/pure/badge.svg?branch=master)](https://coveralls.io/github/go-playground/pure?branch=master)
66
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/pure)](https://goreportcard.com/report/github.com/go-playground/pure)
@@ -11,6 +11,8 @@ package pure
1111
Pure is a fast radix-tree based HTTP router that sticks to the native implementations of Go's "net/http" package;
1212
in essence, keeping the handler implementations 'pure' by using Go 1.7's "context" package.
1313

14+
This makes heavy usage of `github.com/go-playground/pkg` for HTTP abstractions.
15+
1416
Why Another HTTP Router?
1517
------------------------
1618
I initially created [lars](https://github.com/go-playground/lars), which I still maintain, that wraps the native implementation, think of this package as a Go pure implementation of [lars](https://github.com/go-playground/lars)
@@ -156,40 +158,42 @@ Other middleware will be listed under the _examples/middleware/... folder for a
156158

157159
Benchmarks
158160
-----------
159-
Run on i5-7600 16 GB DDR4-2400 using Go version go1.8.1 linux/amd64
161+
Run on i5-7600 16 GB DDR4-2400 using Go version go1.12.5 darwin/amd64
160162

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.
163+
NOTICE: pure uses a custom version of [httprouter](https://github.com/julienschmidt/httprouter)'s radix tree, benchmarks can be found [here](https://github.com/deankarn/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.
162164

163165
```go
164166
go test -bench=. -benchmem=true
165167
#GithubAPI Routes: 203
166-
Pure: 37544 Bytes
168+
Pure: 37096 Bytes
167169

168170
#GPlusAPI Routes: 13
169171
Pure: 2792 Bytes
170172

171173
#ParseAPI Routes: 26
172-
Pure: 5056 Bytes
174+
Pure: 5040 Bytes
173175

174176
#Static Routes: 157
175-
Pure: 21208 Bytes
176-
177-
BenchmarkPure_Param 10000000 130 ns/op 256 B/op 1 allocs/op
178-
BenchmarkPure_Param5 10000000 171 ns/op 256 B/op 1 allocs/op
179-
BenchmarkPure_Param20 5000000 316 ns/op 256 B/op 1 allocs/op
180-
BenchmarkPure_ParamWrite 10000000 171 ns/op 256 B/op 1 allocs/op
181-
BenchmarkPure_GithubStatic 50000000 35.8 ns/op 0 B/op 0 allocs/op
182-
BenchmarkPure_GithubParam 10000000 187 ns/op 256 B/op 1 allocs/op
183-
BenchmarkPure_GithubAll 50000 35691 ns/op 42754 B/op 167 allocs/op
184-
BenchmarkPure_GPlusStatic 100000000 22.7 ns/op 0 B/op 0 allocs/op
185-
BenchmarkPure_GPlusParam 10000000 152 ns/op 256 B/op 1 allocs/op
186-
BenchmarkPure_GPlus2Params 10000000 173 ns/op 256 B/op 1 allocs/op
187-
BenchmarkPure_GPlusAll 1000000 1902 ns/op 2816 B/op 11 allocs/op
188-
BenchmarkPure_ParseStatic 100000000 23.5 ns/op 0 B/op 0 allocs/op
189-
BenchmarkPure_ParseParam 10000000 136 ns/op 256 B/op 1 allocs/op
190-
BenchmarkPure_Parse2Params 10000000 149 ns/op 256 B/op 1 allocs/op
191-
BenchmarkPure_ParseAll 500000 3091 ns/op 4096 B/op 16 allocs/op
192-
BenchmarkPure_StaticAll 200000 8547 ns/op 0 B/op 0 allocs/op
177+
HttpServeMux: 14992 Bytes
178+
Pure: 21096 Bytes
179+
180+
181+
BenchmarkPure_Param 10000000 184 ns/op 384 B/op 2 allocs/op
182+
BenchmarkPure_Param5 10000000 236 ns/op 384 B/op 2 allocs/op
183+
BenchmarkPure_Param20 5000000 393 ns/op 384 B/op 2 allocs/op
184+
BenchmarkPure_ParamWrite 5000000 240 ns/op 384 B/op 2 allocs/op
185+
BenchmarkPure_GithubStatic 50000000 36.2 ns/op 0 B/op 0 allocs/op
186+
BenchmarkPureGithubParam 10000000 230 ns/op 384 B/op 2 allocs/op
187+
BenchmarkPure_GithubAll 30000 43887 ns/op 64130 B/op 334 allocs/op
188+
BenchmarkPure_GPlusStatic 50000000 22.8 ns/op 0 B/op 0 allocs/op
189+
BenchmarkPure_GPlusParam 10000000 192 ns/op 384 B/op 2 allocs/op
190+
BenchmarkPure_GPlus2Params 10000000 211 ns/op 384 B/op 2 allocs/op
191+
BenchmarkPure_GPlusAll 500000 2457 ns/op 4224 B/op 22 allocs/op
192+
BenchmarkPure_ParseStatic 100000000 23.7 ns/op 0 B/op 0 allocs/op
193+
BenchmarkPure_ParseParam 10000000 177 ns/op 384 B/op 2 allocs/op
194+
BenchmarkPure_Parse2Params 10000000 193 ns/op 384 B/op 2 allocs/op
195+
BenchmarkPure_ParseAll 500000 3751 ns/op 6144 B/op 32 allocs/op
196+
BenchmarkPure_StaticAll 200000 8574 ns/op 0 B/op 0 allocs/op
193197
```
194198

195199
Package Versioning

constants.go

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,12 @@ package pure
22

33
// HTTP Constant Terms and Variables
44
const (
5-
6-
//-------------
7-
// Media types
8-
//-------------
9-
10-
ApplicationJSON = "application/json"
11-
ApplicationJSONCharsetUTF8 = ApplicationJSON + "; " + CharsetUTF8
12-
ApplicationJavaScript = "application/javascript"
13-
ApplicationJavaScriptCharsetUTF8 = ApplicationJavaScript + "; " + CharsetUTF8
14-
ApplicationXML = "application/xml"
15-
ApplicationXMLCharsetUTF8 = ApplicationXML + "; " + CharsetUTF8
16-
ApplicationForm = "application/x-www-form-urlencoded"
17-
ApplicationQueryParams = ""
18-
ApplicationProtobuf = "application/protobuf"
19-
ApplicationMsgpack = "application/msgpack"
20-
TextHTML = "text/html"
21-
TextHTMLCharsetUTF8 = TextHTML + "; " + CharsetUTF8
22-
TextPlain = "text/plain"
23-
TextPlainCharsetUTF8 = TextPlain + "; " + CharsetUTF8
24-
MultipartForm = "multipart/form-data"
25-
OctetStream = "application/octet-stream"
26-
27-
//---------
28-
// Charset
29-
//---------
30-
31-
CharsetUTF8 = "charset=utf-8"
32-
33-
//---------
34-
// Headers
35-
//---------
36-
37-
AcceptedLanguage = "Accept-Language"
38-
AcceptEncoding = "Accept-Encoding"
39-
Authorization = "Authorization"
40-
ContentDisposition = "Content-Disposition"
41-
ContentEncoding = "Content-Encoding"
42-
ContentLength = "Content-Length"
43-
ContentType = "Content-Type"
44-
Location = "Location"
45-
Upgrade = "Upgrade"
46-
Vary = "Vary"
47-
WWWAuthenticate = "WWW-Authenticate"
48-
XForwardedFor = "X-Forwarded-For"
49-
XRealIP = "X-Real-Ip"
50-
Allow = "Allow"
51-
Origin = "Origin"
52-
53-
Gzip = "gzip"
5+
// use constants from github.com/go-playground/net/http
546

557
WildcardParam = "*wildcard"
56-
57-
basePath = "/"
58-
blank = ""
59-
60-
slashByte = '/'
61-
paramByte = ':'
62-
wildByte = '*'
8+
basePath = "/"
9+
blank = ""
10+
slashByte = '/'
11+
paramByte = ':'
12+
wildByte = '*'
6313
)

form_decoder.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

go.mod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module github.com/go-playground/pure
2+
3+
require (
4+
github.com/go-playground/pkg v0.0.0-20190511145249-fa4bcb050f1d
5+
gopkg.in/go-playground/assert.v1 v1.2.1
6+
)

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
github.com/go-playground/form v3.1.4+incompatible h1:lvKiHVxE2WvzDIoyMnWcjyiBxKt2+uFJyZcPYWsLnjI=
2+
github.com/go-playground/form v3.1.4+incompatible/go.mod h1:lhcKXfTuhRtIZCIKUeJ0b5F207aeQCPbZU09ScKjwWg=
3+
github.com/go-playground/pkg v0.0.0-20190511145249-fa4bcb050f1d h1:dLyXECWWFoQAp49e+ayPJyTcVAVOSAEmZ/QALeOuIfg=
4+
github.com/go-playground/pkg v0.0.0-20190511145249-fa4bcb050f1d/go.mod h1:Wg1j+HqWLhhVIfYdaoOuBzdutBEVcqwvBxgFZRWbybk=
5+
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
6+
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=

group_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,17 @@ func TestGrouplogic(t *testing.T) {
213213

214214
a := p.GroupWithMore("/a", aM)
215215
a.Get("/test", func(w http.ResponseWriter, r *http.Request) {
216-
w.Write([]byte("a-ok"))
216+
_, _ = w.Write([]byte("a-ok"))
217217
})
218218

219219
b := a.GroupWithMore("/b", bM)
220220
b.Get("/test", func(w http.ResponseWriter, r *http.Request) {
221-
w.Write([]byte("b-ok"))
221+
_, _ = w.Write([]byte("b-ok"))
222222
})
223223

224224
c := b.GroupWithMore("/c", cM)
225225
c.Get("/test", func(w http.ResponseWriter, r *http.Request) {
226-
w.Write([]byte("c-ok"))
226+
_, _ = w.Write([]byte("c-ok"))
227227
})
228228

229229
code, body := request(http.MethodGet, "/a/test", p)

0 commit comments

Comments
 (0)