Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@ notifications:
before_install:
- go get -u github.com/go-playground/overalls
- go get -u github.com/mattn/goveralls
# - go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
- go get -u github.com/client9/misspell/cmd/misspell

before_script:
- go vet ./...
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.16.0

script:
- gofmt -d -s .
# - golangci-lint run
- find . -type f | xargs misspell -source=text
- go test -cover -race ./...
- make test
- ./bin/golangci-lint run

after_success: |
[ $TRAVIS_GO_VERSION = 1.12.5 ] &&
Expand Down
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
GOCMD=GO111MODULE=on go

linters-install:
@golangci-lint --version >/dev/null 2>&1 || { \
echo "installing linting tools..."; \
$(GOCMD) get github.com/golangci/golangci-lint/cmd/golangci-lint; \
}

lint: linters-install
golangci-lint run

test:
$(GOCMD) test -cover -race ./...

bench:
$(GOCMD) test -bench=. -benchmem ./...

.PHONY: linters-install lint test bench
50 changes: 27 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pure
============
<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)
<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)
[![Build Status](https://travis-ci.org/go-playground/pure.svg?branch=master)](https://travis-ci.org/go-playground/pure)
[![Coverage Status](https://coveralls.io/repos/github/go-playground/pure/badge.svg?branch=master)](https://coveralls.io/github/go-playground/pure?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/pure)](https://goreportcard.com/report/github.com/go-playground/pure)
Expand All @@ -11,6 +11,8 @@ package pure
Pure is a fast radix-tree based HTTP router that sticks to the native implementations of Go's "net/http" package;
in essence, keeping the handler implementations 'pure' by using Go 1.7's "context" package.

This makes heavy usage of `github.com/go-playground/pkg` for HTTP abstractions.

Why Another HTTP Router?
------------------------
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)
Expand Down Expand Up @@ -156,40 +158,42 @@ Other middleware will be listed under the _examples/middleware/... folder for a

Benchmarks
-----------
Run on i5-7600 16 GB DDR4-2400 using Go version go1.8.1 linux/amd64
Run on i5-7600 16 GB DDR4-2400 using Go version go1.12.5 darwin/amd64

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

```go
go test -bench=. -benchmem=true
#GithubAPI Routes: 203
Pure: 37544 Bytes
Pure: 37096 Bytes

#GPlusAPI Routes: 13
Pure: 2792 Bytes

#ParseAPI Routes: 26
Pure: 5056 Bytes
Pure: 5040 Bytes

#Static Routes: 157
Pure: 21208 Bytes

BenchmarkPure_Param 10000000 130 ns/op 256 B/op 1 allocs/op
BenchmarkPure_Param5 10000000 171 ns/op 256 B/op 1 allocs/op
BenchmarkPure_Param20 5000000 316 ns/op 256 B/op 1 allocs/op
BenchmarkPure_ParamWrite 10000000 171 ns/op 256 B/op 1 allocs/op
BenchmarkPure_GithubStatic 50000000 35.8 ns/op 0 B/op 0 allocs/op
BenchmarkPure_GithubParam 10000000 187 ns/op 256 B/op 1 allocs/op
BenchmarkPure_GithubAll 50000 35691 ns/op 42754 B/op 167 allocs/op
BenchmarkPure_GPlusStatic 100000000 22.7 ns/op 0 B/op 0 allocs/op
BenchmarkPure_GPlusParam 10000000 152 ns/op 256 B/op 1 allocs/op
BenchmarkPure_GPlus2Params 10000000 173 ns/op 256 B/op 1 allocs/op
BenchmarkPure_GPlusAll 1000000 1902 ns/op 2816 B/op 11 allocs/op
BenchmarkPure_ParseStatic 100000000 23.5 ns/op 0 B/op 0 allocs/op
BenchmarkPure_ParseParam 10000000 136 ns/op 256 B/op 1 allocs/op
BenchmarkPure_Parse2Params 10000000 149 ns/op 256 B/op 1 allocs/op
BenchmarkPure_ParseAll 500000 3091 ns/op 4096 B/op 16 allocs/op
BenchmarkPure_StaticAll 200000 8547 ns/op 0 B/op 0 allocs/op
HttpServeMux: 14992 Bytes
Pure: 21096 Bytes


BenchmarkPure_Param 10000000 184 ns/op 384 B/op 2 allocs/op
BenchmarkPure_Param5 10000000 236 ns/op 384 B/op 2 allocs/op
BenchmarkPure_Param20 5000000 393 ns/op 384 B/op 2 allocs/op
BenchmarkPure_ParamWrite 5000000 240 ns/op 384 B/op 2 allocs/op
BenchmarkPure_GithubStatic 50000000 36.2 ns/op 0 B/op 0 allocs/op
BenchmarkPureGithubParam 10000000 230 ns/op 384 B/op 2 allocs/op
BenchmarkPure_GithubAll 30000 43887 ns/op 64130 B/op 334 allocs/op
BenchmarkPure_GPlusStatic 50000000 22.8 ns/op 0 B/op 0 allocs/op
BenchmarkPure_GPlusParam 10000000 192 ns/op 384 B/op 2 allocs/op
BenchmarkPure_GPlus2Params 10000000 211 ns/op 384 B/op 2 allocs/op
BenchmarkPure_GPlusAll 500000 2457 ns/op 4224 B/op 22 allocs/op
BenchmarkPure_ParseStatic 100000000 23.7 ns/op 0 B/op 0 allocs/op
BenchmarkPure_ParseParam 10000000 177 ns/op 384 B/op 2 allocs/op
BenchmarkPure_Parse2Params 10000000 193 ns/op 384 B/op 2 allocs/op
BenchmarkPure_ParseAll 500000 3751 ns/op 6144 B/op 32 allocs/op
BenchmarkPure_StaticAll 200000 8574 ns/op 0 B/op 0 allocs/op
```

Package Versioning
Expand Down
62 changes: 6 additions & 56 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,12 @@ package pure

// HTTP Constant Terms and Variables
const (

//-------------
// Media types
//-------------

ApplicationJSON = "application/json"
ApplicationJSONCharsetUTF8 = ApplicationJSON + "; " + CharsetUTF8
ApplicationJavaScript = "application/javascript"
ApplicationJavaScriptCharsetUTF8 = ApplicationJavaScript + "; " + CharsetUTF8
ApplicationXML = "application/xml"
ApplicationXMLCharsetUTF8 = ApplicationXML + "; " + CharsetUTF8
ApplicationForm = "application/x-www-form-urlencoded"
ApplicationQueryParams = ""
ApplicationProtobuf = "application/protobuf"
ApplicationMsgpack = "application/msgpack"
TextHTML = "text/html"
TextHTMLCharsetUTF8 = TextHTML + "; " + CharsetUTF8
TextPlain = "text/plain"
TextPlainCharsetUTF8 = TextPlain + "; " + CharsetUTF8
MultipartForm = "multipart/form-data"
OctetStream = "application/octet-stream"

//---------
// Charset
//---------

CharsetUTF8 = "charset=utf-8"

//---------
// Headers
//---------

AcceptedLanguage = "Accept-Language"
AcceptEncoding = "Accept-Encoding"
Authorization = "Authorization"
ContentDisposition = "Content-Disposition"
ContentEncoding = "Content-Encoding"
ContentLength = "Content-Length"
ContentType = "Content-Type"
Location = "Location"
Upgrade = "Upgrade"
Vary = "Vary"
WWWAuthenticate = "WWW-Authenticate"
XForwardedFor = "X-Forwarded-For"
XRealIP = "X-Real-Ip"
Allow = "Allow"
Origin = "Origin"

Gzip = "gzip"
// use constants from github.com/go-playground/net/http

WildcardParam = "*wildcard"

basePath = "/"
blank = ""

slashByte = '/'
paramByte = ':'
wildByte = '*'
basePath = "/"
blank = ""
slashByte = '/'
paramByte = ':'
wildByte = '*'
)
17 changes: 0 additions & 17 deletions form_decoder.go

This file was deleted.

6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module github.com/go-playground/pure

require (
github.com/go-playground/pkg v0.0.0-20190511145249-fa4bcb050f1d
gopkg.in/go-playground/assert.v1 v1.2.1
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
github.com/go-playground/form v3.1.4+incompatible h1:lvKiHVxE2WvzDIoyMnWcjyiBxKt2+uFJyZcPYWsLnjI=
github.com/go-playground/form v3.1.4+incompatible/go.mod h1:lhcKXfTuhRtIZCIKUeJ0b5F207aeQCPbZU09ScKjwWg=
github.com/go-playground/pkg v0.0.0-20190511145249-fa4bcb050f1d h1:dLyXECWWFoQAp49e+ayPJyTcVAVOSAEmZ/QALeOuIfg=
github.com/go-playground/pkg v0.0.0-20190511145249-fa4bcb050f1d/go.mod h1:Wg1j+HqWLhhVIfYdaoOuBzdutBEVcqwvBxgFZRWbybk=
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
6 changes: 3 additions & 3 deletions group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,17 @@ func TestGrouplogic(t *testing.T) {

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

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

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

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