Ai
1 Star 0 Fork 0

jobily/go-http-routing-benchmark

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
routers_test.go 1.91 KB
一键复制 编辑 原始数据 按行查看 历史
dtmkeng 提交于 2019-10-23 00:49 +08:00 . add new framework Aero
package main
import (
"net/http"
"net/http/httptest"
"testing"
)
var (
// load functions of all routers
routers = []struct {
name string
load func(routes []route) http.Handler
}{
{"Ace", loadAce},
{"Aero", loadAero},
{"Bear", loadBear},
{"Beego", loadBeego},
{"Bone", loadBone},
{"Chi", loadChi},
{"CloudyKitRouter", loadCloudyKitRouter},
{"Denco", loadDenco},
{"Echo", loadEcho},
{"Gin", loadGin},
{"GocraftWeb", loadGocraftWeb},
{"Goji", loadGoji},
{"Gojiv2", loadGojiv2},
{"GoJsonRest", loadGoJsonRest},
{"GoRestful", loadGoRestful},
{"GorillaMux", loadGorillaMux},
{"GowwwRouter", loadGowwwRouter},
{"HttpRouter", loadHttpRouter},
{"HttpTreeMux", loadHttpTreeMux},
//{"Kocha", loadKocha},
{"LARS", loadLARS},
{"Macaron", loadMacaron},
{"Martini", loadMartini},
{"Pat", loadPat},
{"Possum", loadPossum},
{"R2router", loadR2router},
// {"Revel", loadRevel},
{"Rivet", loadRivet},
//{"Tango", loadTango},
{"TigerTonic", loadTigerTonic},
{"Traffic", loadTraffic},
{"Vulcan", loadVulcan},
// {"Zeus", loadZeus},
}
// all APIs
apis = []struct {
name string
routes []route
}{
{"GitHub", githubAPI},
{"GPlus", gplusAPI},
{"Parse", parseAPI},
{"Static", staticRoutes},
}
)
func TestRouters(t *testing.T) {
loadTestHandler = true
for _, router := range routers {
req, _ := http.NewRequest("GET", "/", nil)
u := req.URL
rq := u.RawQuery
for _, api := range apis {
r := router.load(api.routes)
for _, route := range api.routes {
w := httptest.NewRecorder()
req.Method = route.method
req.RequestURI = route.path
u.Path = route.path
u.RawQuery = rq
r.ServeHTTP(w, req)
if w.Code != 200 || w.Body.String() != route.path {
t.Errorf(
"%s in API %s: %d - %s; expected %s %s\n",
router.name, api.name, w.Code, w.Body.String(), route.method, route.path,
)
}
}
}
}
loadTestHandler = false
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hubo/go-http-routing-benchmark.git
git@gitee.com:hubo/go-http-routing-benchmark.git
hubo
go-http-routing-benchmark
go-http-routing-benchmark
master

搜索帮助