Skip to content

Add Golossus router stable version #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Of course the tested routers can be used for any kind of HTTP request → handle
* [Denco](https://github.com/naoina/denco)
* [Gocraft Web](https://github.com/gocraft/web)
* [Goji](https://github.com/zenazn/goji/)
* [Golossus](https://github.com/golossus/routing)
* [Gorilla Mux](http://www.gorillatoolkit.org/pkg/mux)
* [http.ServeMux](http://golang.org/pkg/net/http/#ServeMux)
* [HttpRouter](https://github.com/julienschmidt/httprouter)
Expand Down
24 changes: 24 additions & 0 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ func BenchmarkGoJsonRest_Param(b *testing.B) {
r, _ := http.NewRequest("GET", "/user/gordon", nil)
benchRequest(b, router, r)
}
func BenchmarkGolossus_Param(b *testing.B) {
router := loadGolossusSingle("GET", "/user/{name}", httpHandlerFunc)

r, _ := http.NewRequest("GET", "/user/gordon", nil)
benchRequest(b, router, r)
}
func BenchmarkGoRestful_Param(b *testing.B) {
router := loadGoRestfulSingle("GET", "/user/{name}", goRestfulHandler)

Expand Down Expand Up @@ -398,6 +404,12 @@ func BenchmarkGoJsonRest_Param5(b *testing.B) {
r, _ := http.NewRequest("GET", fiveRoute, nil)
benchRequest(b, handler, r)
}
func BenchmarkGolossus_Param5(b *testing.B) {
handler := loadGolossusSingle("GET", fiveBrace, httpHandlerFunc)

r, _ := http.NewRequest("GET", fiveRoute, nil)
benchRequest(b, handler, r)
}
func BenchmarkGoRestful_Param5(b *testing.B) {
router := loadGoRestfulSingle("GET", fiveBrace, goRestfulHandler)

Expand Down Expand Up @@ -608,6 +620,12 @@ func BenchmarkGoJsonRest_Param20(b *testing.B) {
r, _ := http.NewRequest("GET", twentyRoute, nil)
benchRequest(b, handler, r)
}
func BenchmarkGolossus_Param20(b *testing.B) {
handler := loadGolossusSingle("GET", twentyBrace, httpHandlerFunc)

r, _ := http.NewRequest("GET", twentyRoute, nil)
benchRequest(b, handler, r)
}
func BenchmarkGoRestful_Param20(b *testing.B) {
handler := loadGoRestfulSingle("GET", twentyBrace, goRestfulHandler)

Expand Down Expand Up @@ -814,6 +832,12 @@ func BenchmarkGoJsonRest_ParamWrite(b *testing.B) {
r, _ := http.NewRequest("GET", "/user/gordon", nil)
benchRequest(b, handler, r)
}
func BenchmarkGolossus_ParamWrite(b *testing.B) {
handler := loadGolossusSingle("GET", "/user/{name}", golossusHandlerWrite)

r, _ := http.NewRequest("GET", "/user/gordon", nil)
benchRequest(b, handler, r)
}
func BenchmarkGoRestful_ParamWrite(b *testing.B) {
handler := loadGoRestfulSingle("GET", "/user/{name}", goRestfulHandlerWrite)

Expand Down
15 changes: 15 additions & 0 deletions github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ var (
githubGoji http.Handler
githubGojiv2 http.Handler
githubGoJsonRest http.Handler
githubGolossus http.Handler
githubGoRestful http.Handler
githubGorillaMux http.Handler
githubGowwwRouter http.Handler
Expand Down Expand Up @@ -354,6 +355,9 @@ func init() {
calcMem("GoJsonRest", func() {
githubGoJsonRest = loadGoJsonRest(githubAPI)
})
calcMem("Golossus", func() {
githubGolossus = loadGolossus(githubAPI)
})
calcMem("GoRestful", func() {
githubGoRestful = loadGoRestful(githubAPI)
})
Expand Down Expand Up @@ -472,6 +476,10 @@ func BenchmarkGoRestful_GithubStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/user/repos", nil)
benchRequest(b, githubGoRestful, req)
}
func BenchmarkGolossus_GithubStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/user/repos", nil)
benchRequest(b, githubGolossus, req)
}
func BenchmarkGoJsonRest_GithubStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/user/repos", nil)
benchRequest(b, githubGoJsonRest, req)
Expand Down Expand Up @@ -608,6 +616,10 @@ func BenchmarkGoJsonRest_GithubParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/repos/julienschmidt/httprouter/stargazers", nil)
benchRequest(b, githubGoJsonRest, req)
}
func BenchmarkGolossus_GithubParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/repos/julienschmidt/httprouter/stargazers", nil)
benchRequest(b, githubGolossus, req)
}
func BenchmarkGoRestful_GithubParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/repos/julienschmidt/httprouter/stargazers", nil)
benchRequest(b, githubGoRestful, req)
Expand Down Expand Up @@ -730,6 +742,9 @@ func BenchmarkGojiv2_GithubAll(b *testing.B) {
func BenchmarkGoJsonRest_GithubAll(b *testing.B) {
benchRoutes(b, githubGoJsonRest, githubAPI)
}
func BenchmarkGolossus_GithubAll(b *testing.B) {
benchRoutes(b, githubGolossus, githubAPI)
}
func BenchmarkGoRestful_GithubAll(b *testing.B) {
benchRoutes(b, githubGoRestful, githubAPI)
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/go-playground/lars v4.0.1+incompatible
github.com/go-zoo/bone v1.3.0
github.com/gocraft/web v0.0.0-20190207150652-9707327fb69b
github.com/golossus/routing v1.0.0
github.com/gorilla/mux v1.7.3
github.com/gorilla/sessions v1.2.0 // indirect
github.com/gorilla/websocket v1.4.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golossus/routing v1.0.0 h1:T8sPJmCtivMcKkp7F50OiRZrcqUqAJ6m9Xaw0Vf2ewk=
github.com/golossus/routing v1.0.0/go.mod h1:WmyBNlhhC8Gqb1sGOmRKxgeBCE0/Uw6WCdBrR0z+ZAM=
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
Expand Down
19 changes: 19 additions & 0 deletions gplus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var (
gplusGoji http.Handler
gplusGojiv2 http.Handler
gplusGoJsonRest http.Handler
gplusGolossus http.Handler
gplusGoRestful http.Handler
gplusGorillaMux http.Handler
gplusGowwwRouter http.Handler
Expand Down Expand Up @@ -116,6 +117,9 @@ func init() {
calcMem("GoJsonRest", func() {
gplusGoJsonRest = loadGoJsonRest(gplusAPI)
})
calcMem("Golossus", func() {
gplusGolossus = loadGolossus(gplusAPI)
})
calcMem("GoRestful", func() {
gplusGoRestful = loadGoRestful(gplusAPI)
})
Expand Down Expand Up @@ -234,6 +238,10 @@ func BenchmarkGoJsonRest_GPlusStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/people", nil)
benchRequest(b, gplusGoJsonRest, req)
}
func BenchmarkGolossus_GPlusStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/people", nil)
benchRequest(b, gplusGolossus, req)
}
func BenchmarkGoRestful_GPlusStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/people", nil)
benchRequest(b, gplusGoRestful, req)
Expand Down Expand Up @@ -370,6 +378,10 @@ func BenchmarkGoJsonRest_GPlusParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327", nil)
benchRequest(b, gplusGoJsonRest, req)
}
func BenchmarkGolossus_GPlusParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327", nil)
benchRequest(b, gplusGolossus, req)
}
func BenchmarkGoRestful_GPlusParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327", nil)
benchRequest(b, gplusGoRestful, req)
Expand Down Expand Up @@ -506,6 +518,10 @@ func BenchmarkGoJsonRest_GPlus2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327/activities/123456789", nil)
benchRequest(b, gplusGoJsonRest, req)
}
func BenchmarkGolossus_GPlus2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327/activities/123456789", nil)
benchRequest(b, gplusGolossus, req)
}
func BenchmarkGoRestful_GPlus2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327/activities/123456789", nil)
benchRequest(b, gplusGoRestful, req)
Expand Down Expand Up @@ -628,6 +644,9 @@ func BenchmarkGojiv2_GPlusAll(b *testing.B) {
func BenchmarkGoJsonRest_GPlusAll(b *testing.B) {
benchRoutes(b, gplusGoJsonRest, gplusAPI)
}
func BenchmarkGolossus_GPlusAll(b *testing.B) {
benchRoutes(b, gplusGolossus, gplusAPI)
}
func BenchmarkGoRestful_GPlusAll(b *testing.B) {
benchRoutes(b, gplusGoRestful, gplusAPI)
}
Expand Down
19 changes: 19 additions & 0 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var (
parseGoji http.Handler
parseGojiv2 http.Handler
parseGoJsonRest http.Handler
parseGolossus http.Handler
parseGoRestful http.Handler
parseGorillaMux http.Handler
parseGowwwRouter http.Handler
Expand Down Expand Up @@ -133,6 +134,9 @@ func init() {
calcMem("GoJsonRest", func() {
parseGoJsonRest = loadGoJsonRest(parseAPI)
})
calcMem("Golossus", func() {
parseGolossus = loadGolossus(parseAPI)
})
calcMem("GoRestful", func() {
parseGoRestful = loadGoRestful(parseAPI)
})
Expand Down Expand Up @@ -251,6 +255,10 @@ func BenchmarkGoJsonRest_ParseStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/users", nil)
benchRequest(b, parseGoJsonRest, req)
}
func BenchmarkGolossus_ParseStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/users", nil)
benchRequest(b, parseGolossus, req)
}
func BenchmarkGoRestful_ParseStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/users", nil)
benchRequest(b, parseGoRestful, req)
Expand Down Expand Up @@ -387,6 +395,10 @@ func BenchmarkGoJsonRest_ParseParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go", nil)
benchRequest(b, parseGoJsonRest, req)
}
func BenchmarkGolossus_ParseParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go", nil)
benchRequest(b, parseGolossus, req)
}
func BenchmarkGoRestful_ParseParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go", nil)
benchRequest(b, parseGoRestful, req)
Expand Down Expand Up @@ -523,6 +535,10 @@ func BenchmarkGoJsonRest_Parse2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go/123456789", nil)
benchRequest(b, parseGoJsonRest, req)
}
func BenchmarkGolossus_Parse2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go/123456789", nil)
benchRequest(b, parseGolossus, req)
}
func BenchmarkGoRestful_Parse2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go/123456789", nil)
benchRequest(b, parseGoRestful, req)
Expand Down Expand Up @@ -645,6 +661,9 @@ func BenchmarkGojiv2_ParseAll(b *testing.B) {
func BenchmarkGoJsonRest_ParseAll(b *testing.B) {
benchRoutes(b, parseGoJsonRest, parseAPI)
}
func BenchmarkGolossus_ParseAll(b *testing.B) {
benchRoutes(b, parseGolossus, parseAPI)
}
func BenchmarkGoRestful_ParseAll(b *testing.B) {
benchRoutes(b, parseGoRestful, parseAPI)
}
Expand Down
35 changes: 35 additions & 0 deletions routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/go-martini/martini"
"github.com/go-zoo/bone"
"github.com/gocraft/web"
golossus "github.com/golossus/routing"
"github.com/gorilla/mux"
gowwwrouter "github.com/gowww/router"
"github.com/julienschmidt/httprouter"
Expand Down Expand Up @@ -778,6 +779,40 @@ func loadGoJsonRestSingle(method, path string, hfunc rest.HandlerFunc) http.Hand
return api.MakeHandler()
}

//Golossus
func golossusHandlerWrite(w http.ResponseWriter, r *http.Request) {
params := golossus.GetURLParameters(r)
name, _ := params.GetByName("name")
io.WriteString(w, name)
}

func loadGolossus(routes []route) http.Handler {
h := httpHandlerFunc
if loadTestHandler {
h = httpHandlerFuncTest
}

re := regexp.MustCompile(":([^/]*)")
router := golossus.NewRouter()
for _, route := range routes {
err := router.Register(
route.method,
re.ReplaceAllString(route.path, "{$1}"),
h,
)
if err != nil {
fmt.Println(err)
}
}
return &router
}

func loadGolossusSingle(method, path string, handle http.HandlerFunc) http.Handler {
router := golossus.NewRouter()
router.Register(method, path, handle)
return &router
}

// go-restful
func goRestfulHandler(r *restful.Request, w *restful.Response) {}

Expand Down
1 change: 1 addition & 0 deletions routers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
{"Goji", loadGoji},
{"Gojiv2", loadGojiv2},
{"GoJsonRest", loadGoJsonRest},
{"Golossus", loadGolossus},
{"GoRestful", loadGoRestful},
{"GorillaMux", loadGorillaMux},
{"GowwwRouter", loadGowwwRouter},
Expand Down
7 changes: 7 additions & 0 deletions static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ var (
staticGoji http.Handler
staticGojiv2 http.Handler
staticGoJsonRest http.Handler
staticGolossus http.Handler
staticGoRestful http.Handler
staticGorillaMux http.Handler
staticGowwwRouter http.Handler
Expand Down Expand Up @@ -260,6 +261,9 @@ func init() {
calcMem("GoJsonRest", func() {
staticGoJsonRest = loadGoJsonRest(staticRoutes)
})
calcMem("Golossus", func() {
staticGolossus = loadGolossus(staticRoutes)
})
calcMem("GoRestful", func() {
staticGoRestful = loadGoRestful(staticRoutes)
})
Expand Down Expand Up @@ -368,6 +372,9 @@ func BenchmarkGojiv2_StaticAll(b *testing.B) {
func BenchmarkGoJsonRest_StaticAll(b *testing.B) {
benchRoutes(b, staticGoJsonRest, staticRoutes)
}
func BenchmarkGolossus_StaticAll(b *testing.B) {
benchRoutes(b, staticGolossus, staticRoutes)
}
func BenchmarkGoRestful_StaticAll(b *testing.B) {
benchRoutes(b, staticGoRestful, staticRoutes)
}
Expand Down