2015-03-27 23:21:30 +02:00
|
|
|
package echo
|
2015-03-01 19:45:13 +02:00
|
|
|
|
2015-04-01 17:05:54 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
2015-04-06 05:08:52 +02:00
|
|
|
"net/http"
|
2016-11-13 19:36:57 +02:00
|
|
|
"strings"
|
2015-04-01 17:05:54 +02:00
|
|
|
"testing"
|
2015-05-31 00:20:36 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2015-04-01 17:05:54 +02:00
|
|
|
)
|
2015-03-01 19:45:13 +02:00
|
|
|
|
2015-04-09 23:59:31 +02:00
|
|
|
var (
|
2016-11-12 19:42:25 +02:00
|
|
|
staticRoutes = []Route{
|
|
|
|
{"GET", "/", ""},
|
|
|
|
{"GET", "/cmd.html", ""},
|
|
|
|
{"GET", "/code.html", ""},
|
|
|
|
{"GET", "/contrib.html", ""},
|
|
|
|
{"GET", "/contribute.html", ""},
|
|
|
|
{"GET", "/debugging_with_gdb.html", ""},
|
|
|
|
{"GET", "/docs.html", ""},
|
|
|
|
{"GET", "/effective_go.html", ""},
|
|
|
|
{"GET", "/files.log", ""},
|
|
|
|
{"GET", "/gccgo_contribute.html", ""},
|
|
|
|
{"GET", "/gccgo_install.html", ""},
|
|
|
|
{"GET", "/go-logo-black.png", ""},
|
|
|
|
{"GET", "/go-logo-blue.png", ""},
|
|
|
|
{"GET", "/go-logo-white.png", ""},
|
|
|
|
{"GET", "/go1.1.html", ""},
|
|
|
|
{"GET", "/go1.2.html", ""},
|
|
|
|
{"GET", "/go1.html", ""},
|
|
|
|
{"GET", "/go1compat.html", ""},
|
|
|
|
{"GET", "/go_faq.html", ""},
|
|
|
|
{"GET", "/go_mem.html", ""},
|
|
|
|
{"GET", "/go_spec.html", ""},
|
|
|
|
{"GET", "/help.html", ""},
|
|
|
|
{"GET", "/ie.css", ""},
|
|
|
|
{"GET", "/install-source.html", ""},
|
|
|
|
{"GET", "/install.html", ""},
|
|
|
|
{"GET", "/logo-153x55.png", ""},
|
|
|
|
{"GET", "/Makefile", ""},
|
|
|
|
{"GET", "/root.html", ""},
|
|
|
|
{"GET", "/share.png", ""},
|
|
|
|
{"GET", "/sieve.gif", ""},
|
|
|
|
{"GET", "/tos.html", ""},
|
|
|
|
{"GET", "/articles/", ""},
|
|
|
|
{"GET", "/articles/go_command.html", ""},
|
|
|
|
{"GET", "/articles/index.html", ""},
|
|
|
|
{"GET", "/articles/wiki/", ""},
|
|
|
|
{"GET", "/articles/wiki/edit.html", ""},
|
|
|
|
{"GET", "/articles/wiki/final-noclosure.go", ""},
|
|
|
|
{"GET", "/articles/wiki/final-noerror.go", ""},
|
|
|
|
{"GET", "/articles/wiki/final-parsetemplate.go", ""},
|
|
|
|
{"GET", "/articles/wiki/final-template.go", ""},
|
|
|
|
{"GET", "/articles/wiki/final.go", ""},
|
|
|
|
{"GET", "/articles/wiki/get.go", ""},
|
|
|
|
{"GET", "/articles/wiki/http-sample.go", ""},
|
|
|
|
{"GET", "/articles/wiki/index.html", ""},
|
|
|
|
{"GET", "/articles/wiki/Makefile", ""},
|
|
|
|
{"GET", "/articles/wiki/notemplate.go", ""},
|
|
|
|
{"GET", "/articles/wiki/part1-noerror.go", ""},
|
|
|
|
{"GET", "/articles/wiki/part1.go", ""},
|
|
|
|
{"GET", "/articles/wiki/part2.go", ""},
|
|
|
|
{"GET", "/articles/wiki/part3-errorhandling.go", ""},
|
|
|
|
{"GET", "/articles/wiki/part3.go", ""},
|
|
|
|
{"GET", "/articles/wiki/test.bash", ""},
|
|
|
|
{"GET", "/articles/wiki/test_edit.good", ""},
|
|
|
|
{"GET", "/articles/wiki/test_Test.txt.good", ""},
|
|
|
|
{"GET", "/articles/wiki/test_view.good", ""},
|
|
|
|
{"GET", "/articles/wiki/view.html", ""},
|
|
|
|
{"GET", "/codewalk/", ""},
|
|
|
|
{"GET", "/codewalk/codewalk.css", ""},
|
|
|
|
{"GET", "/codewalk/codewalk.js", ""},
|
|
|
|
{"GET", "/codewalk/codewalk.xml", ""},
|
|
|
|
{"GET", "/codewalk/functions.xml", ""},
|
|
|
|
{"GET", "/codewalk/markov.go", ""},
|
|
|
|
{"GET", "/codewalk/markov.xml", ""},
|
|
|
|
{"GET", "/codewalk/pig.go", ""},
|
|
|
|
{"GET", "/codewalk/popout.png", ""},
|
|
|
|
{"GET", "/codewalk/run", ""},
|
|
|
|
{"GET", "/codewalk/sharemem.xml", ""},
|
|
|
|
{"GET", "/codewalk/urlpoll.go", ""},
|
|
|
|
{"GET", "/devel/", ""},
|
|
|
|
{"GET", "/devel/release.html", ""},
|
|
|
|
{"GET", "/devel/weekly.html", ""},
|
|
|
|
{"GET", "/gopher/", ""},
|
|
|
|
{"GET", "/gopher/appenginegopher.jpg", ""},
|
|
|
|
{"GET", "/gopher/appenginegophercolor.jpg", ""},
|
|
|
|
{"GET", "/gopher/appenginelogo.gif", ""},
|
|
|
|
{"GET", "/gopher/bumper.png", ""},
|
|
|
|
{"GET", "/gopher/bumper192x108.png", ""},
|
|
|
|
{"GET", "/gopher/bumper320x180.png", ""},
|
|
|
|
{"GET", "/gopher/bumper480x270.png", ""},
|
|
|
|
{"GET", "/gopher/bumper640x360.png", ""},
|
|
|
|
{"GET", "/gopher/doc.png", ""},
|
|
|
|
{"GET", "/gopher/frontpage.png", ""},
|
|
|
|
{"GET", "/gopher/gopherbw.png", ""},
|
|
|
|
{"GET", "/gopher/gophercolor.png", ""},
|
|
|
|
{"GET", "/gopher/gophercolor16x16.png", ""},
|
|
|
|
{"GET", "/gopher/help.png", ""},
|
|
|
|
{"GET", "/gopher/pkg.png", ""},
|
|
|
|
{"GET", "/gopher/project.png", ""},
|
|
|
|
{"GET", "/gopher/ref.png", ""},
|
|
|
|
{"GET", "/gopher/run.png", ""},
|
|
|
|
{"GET", "/gopher/talks.png", ""},
|
|
|
|
{"GET", "/gopher/pencil/", ""},
|
|
|
|
{"GET", "/gopher/pencil/gopherhat.jpg", ""},
|
|
|
|
{"GET", "/gopher/pencil/gopherhelmet.jpg", ""},
|
|
|
|
{"GET", "/gopher/pencil/gophermega.jpg", ""},
|
|
|
|
{"GET", "/gopher/pencil/gopherrunning.jpg", ""},
|
|
|
|
{"GET", "/gopher/pencil/gopherswim.jpg", ""},
|
|
|
|
{"GET", "/gopher/pencil/gopherswrench.jpg", ""},
|
|
|
|
{"GET", "/play/", ""},
|
|
|
|
{"GET", "/play/fib.go", ""},
|
|
|
|
{"GET", "/play/hello.go", ""},
|
|
|
|
{"GET", "/play/life.go", ""},
|
|
|
|
{"GET", "/play/peano.go", ""},
|
|
|
|
{"GET", "/play/pi.go", ""},
|
|
|
|
{"GET", "/play/sieve.go", ""},
|
|
|
|
{"GET", "/play/solitaire.go", ""},
|
|
|
|
{"GET", "/play/tree.go", ""},
|
|
|
|
{"GET", "/progs/", ""},
|
|
|
|
{"GET", "/progs/cgo1.go", ""},
|
|
|
|
{"GET", "/progs/cgo2.go", ""},
|
|
|
|
{"GET", "/progs/cgo3.go", ""},
|
|
|
|
{"GET", "/progs/cgo4.go", ""},
|
|
|
|
{"GET", "/progs/defer.go", ""},
|
|
|
|
{"GET", "/progs/defer.out", ""},
|
|
|
|
{"GET", "/progs/defer2.go", ""},
|
|
|
|
{"GET", "/progs/defer2.out", ""},
|
|
|
|
{"GET", "/progs/eff_bytesize.go", ""},
|
|
|
|
{"GET", "/progs/eff_bytesize.out", ""},
|
|
|
|
{"GET", "/progs/eff_qr.go", ""},
|
|
|
|
{"GET", "/progs/eff_sequence.go", ""},
|
|
|
|
{"GET", "/progs/eff_sequence.out", ""},
|
|
|
|
{"GET", "/progs/eff_unused1.go", ""},
|
|
|
|
{"GET", "/progs/eff_unused2.go", ""},
|
|
|
|
{"GET", "/progs/error.go", ""},
|
|
|
|
{"GET", "/progs/error2.go", ""},
|
|
|
|
{"GET", "/progs/error3.go", ""},
|
|
|
|
{"GET", "/progs/error4.go", ""},
|
|
|
|
{"GET", "/progs/go1.go", ""},
|
|
|
|
{"GET", "/progs/gobs1.go", ""},
|
|
|
|
{"GET", "/progs/gobs2.go", ""},
|
|
|
|
{"GET", "/progs/image_draw.go", ""},
|
|
|
|
{"GET", "/progs/image_package1.go", ""},
|
|
|
|
{"GET", "/progs/image_package1.out", ""},
|
|
|
|
{"GET", "/progs/image_package2.go", ""},
|
|
|
|
{"GET", "/progs/image_package2.out", ""},
|
|
|
|
{"GET", "/progs/image_package3.go", ""},
|
|
|
|
{"GET", "/progs/image_package3.out", ""},
|
|
|
|
{"GET", "/progs/image_package4.go", ""},
|
|
|
|
{"GET", "/progs/image_package4.out", ""},
|
|
|
|
{"GET", "/progs/image_package5.go", ""},
|
|
|
|
{"GET", "/progs/image_package5.out", ""},
|
|
|
|
{"GET", "/progs/image_package6.go", ""},
|
|
|
|
{"GET", "/progs/image_package6.out", ""},
|
|
|
|
{"GET", "/progs/interface.go", ""},
|
|
|
|
{"GET", "/progs/interface2.go", ""},
|
|
|
|
{"GET", "/progs/interface2.out", ""},
|
|
|
|
{"GET", "/progs/json1.go", ""},
|
|
|
|
{"GET", "/progs/json2.go", ""},
|
|
|
|
{"GET", "/progs/json2.out", ""},
|
|
|
|
{"GET", "/progs/json3.go", ""},
|
|
|
|
{"GET", "/progs/json4.go", ""},
|
|
|
|
{"GET", "/progs/json5.go", ""},
|
|
|
|
{"GET", "/progs/run", ""},
|
|
|
|
{"GET", "/progs/slices.go", ""},
|
|
|
|
{"GET", "/progs/timeout1.go", ""},
|
|
|
|
{"GET", "/progs/timeout2.go", ""},
|
|
|
|
{"GET", "/progs/update.bash", ""},
|
|
|
|
}
|
|
|
|
|
|
|
|
gitHubAPI = []Route{
|
2015-04-09 23:59:31 +02:00
|
|
|
// OAuth Authorizations
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/authorizations", ""},
|
|
|
|
{"GET", "/authorizations/:id", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/authorizations", ""},
|
|
|
|
//{"PUT", "/authorizations/clients/:client_id", ""},
|
|
|
|
//{"PATCH", "/authorizations/:id", ""},
|
|
|
|
{"DELETE", "/authorizations/:id", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/applications/:client_id/tokens/:access_token", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"DELETE", "/applications/:client_id/tokens", ""},
|
|
|
|
{"DELETE", "/applications/:client_id/tokens/:access_token", ""},
|
2015-04-06 06:00:14 +02:00
|
|
|
|
2015-04-09 23:59:31 +02:00
|
|
|
// Activity
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/events", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/events", ""},
|
|
|
|
{"GET", "/networks/:owner/:repo/events", ""},
|
|
|
|
{"GET", "/orgs/:org/events", ""},
|
|
|
|
{"GET", "/users/:user/received_events", ""},
|
|
|
|
{"GET", "/users/:user/received_events/public", ""},
|
|
|
|
{"GET", "/users/:user/events", ""},
|
|
|
|
{"GET", "/users/:user/events/public", ""},
|
|
|
|
{"GET", "/users/:user/events/orgs/:org", ""},
|
|
|
|
{"GET", "/feeds", ""},
|
|
|
|
{"GET", "/notifications", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/notifications", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"PUT", "/notifications", ""},
|
|
|
|
{"PUT", "/repos/:owner/:repo/notifications", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/notifications/threads/:id", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
//{"PATCH", "/notifications/threads/:id", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/notifications/threads/:id/subscription", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"PUT", "/notifications/threads/:id/subscription", ""},
|
|
|
|
{"DELETE", "/notifications/threads/:id/subscription", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/stargazers", ""},
|
|
|
|
{"GET", "/users/:user/starred", ""},
|
|
|
|
{"GET", "/user/starred", ""},
|
|
|
|
{"GET", "/user/starred/:owner/:repo", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"PUT", "/user/starred/:owner/:repo", ""},
|
|
|
|
{"DELETE", "/user/starred/:owner/:repo", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/subscribers", ""},
|
|
|
|
{"GET", "/users/:user/subscriptions", ""},
|
|
|
|
{"GET", "/user/subscriptions", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/subscription", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"PUT", "/repos/:owner/:repo/subscription", ""},
|
|
|
|
{"DELETE", "/repos/:owner/:repo/subscription", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/user/subscriptions/:owner/:repo", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"PUT", "/user/subscriptions/:owner/:repo", ""},
|
|
|
|
{"DELETE", "/user/subscriptions/:owner/:repo", ""},
|
2015-04-06 06:00:14 +02:00
|
|
|
|
2015-04-09 23:59:31 +02:00
|
|
|
// Gists
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/users/:user/gists", ""},
|
|
|
|
{"GET", "/gists", ""},
|
|
|
|
//{"GET", "/gists/public", ""},
|
|
|
|
//{"GET", "/gists/starred", ""},
|
|
|
|
{"GET", "/gists/:id", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/gists", ""},
|
|
|
|
//{"PATCH", "/gists/:id", ""},
|
|
|
|
{"PUT", "/gists/:id/star", ""},
|
|
|
|
{"DELETE", "/gists/:id/star", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/gists/:id/star", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/gists/:id/forks", ""},
|
|
|
|
{"DELETE", "/gists/:id", ""},
|
2015-04-06 06:00:14 +02:00
|
|
|
|
2015-04-09 23:59:31 +02:00
|
|
|
// Git Data
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/git/blobs/:sha", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/repos/:owner/:repo/git/blobs", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/git/commits/:sha", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/repos/:owner/:repo/git/commits", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
//{"GET", "/repos/:owner/:repo/git/refs/*ref", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/git/refs", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/repos/:owner/:repo/git/refs", ""},
|
|
|
|
//{"PATCH", "/repos/:owner/:repo/git/refs/*ref", ""},
|
|
|
|
//{"DELETE", "/repos/:owner/:repo/git/refs/*ref", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/git/tags/:sha", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/repos/:owner/:repo/git/tags", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/git/trees/:sha", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/repos/:owner/:repo/git/trees", ""},
|
2015-04-06 06:00:14 +02:00
|
|
|
|
2015-04-09 23:59:31 +02:00
|
|
|
// Issues
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/issues", ""},
|
|
|
|
{"GET", "/user/issues", ""},
|
|
|
|
{"GET", "/orgs/:org/issues", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/issues", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/issues/:number", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/repos/:owner/:repo/issues", ""},
|
|
|
|
//{"PATCH", "/repos/:owner/:repo/issues/:number", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/assignees", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/assignees/:assignee", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/issues/:number/comments", ""},
|
|
|
|
//{"GET", "/repos/:owner/:repo/issues/comments", ""},
|
|
|
|
//{"GET", "/repos/:owner/:repo/issues/comments/:id", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/repos/:owner/:repo/issues/:number/comments", ""},
|
|
|
|
//{"PATCH", "/repos/:owner/:repo/issues/comments/:id", ""},
|
|
|
|
//{"DELETE", "/repos/:owner/:repo/issues/comments/:id", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/issues/:number/events", ""},
|
|
|
|
//{"GET", "/repos/:owner/:repo/issues/events", ""},
|
|
|
|
//{"GET", "/repos/:owner/:repo/issues/events/:id", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/labels", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/labels/:name", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/repos/:owner/:repo/labels", ""},
|
|
|
|
//{"PATCH", "/repos/:owner/:repo/labels/:name", ""},
|
|
|
|
{"DELETE", "/repos/:owner/:repo/labels/:name", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/issues/:number/labels", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/repos/:owner/:repo/issues/:number/labels", ""},
|
|
|
|
{"DELETE", "/repos/:owner/:repo/issues/:number/labels/:name", ""},
|
|
|
|
{"PUT", "/repos/:owner/:repo/issues/:number/labels", ""},
|
|
|
|
{"DELETE", "/repos/:owner/:repo/issues/:number/labels", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/milestones/:number/labels", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/milestones", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/milestones/:number", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/repos/:owner/:repo/milestones", ""},
|
|
|
|
//{"PATCH", "/repos/:owner/:repo/milestones/:number", ""},
|
|
|
|
{"DELETE", "/repos/:owner/:repo/milestones/:number", ""},
|
2015-04-06 06:00:14 +02:00
|
|
|
|
2015-04-09 23:59:31 +02:00
|
|
|
// Miscellaneous
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/emojis", ""},
|
|
|
|
{"GET", "/gitignore/templates", ""},
|
|
|
|
{"GET", "/gitignore/templates/:name", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/markdown", ""},
|
|
|
|
{"POST", "/markdown/raw", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/meta", ""},
|
|
|
|
{"GET", "/rate_limit", ""},
|
2015-04-06 06:00:14 +02:00
|
|
|
|
2015-04-09 23:59:31 +02:00
|
|
|
// Organizations
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/users/:user/orgs", ""},
|
|
|
|
{"GET", "/user/orgs", ""},
|
|
|
|
{"GET", "/orgs/:org", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
//{"PATCH", "/orgs/:org", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/orgs/:org/members", ""},
|
|
|
|
{"GET", "/orgs/:org/members/:user", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"DELETE", "/orgs/:org/members/:user", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/orgs/:org/public_members", ""},
|
|
|
|
{"GET", "/orgs/:org/public_members/:user", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"PUT", "/orgs/:org/public_members/:user", ""},
|
|
|
|
{"DELETE", "/orgs/:org/public_members/:user", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/orgs/:org/teams", ""},
|
|
|
|
{"GET", "/teams/:id", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/orgs/:org/teams", ""},
|
|
|
|
//{"PATCH", "/teams/:id", ""},
|
|
|
|
{"DELETE", "/teams/:id", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/teams/:id/members", ""},
|
|
|
|
{"GET", "/teams/:id/members/:user", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"PUT", "/teams/:id/members/:user", ""},
|
|
|
|
{"DELETE", "/teams/:id/members/:user", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/teams/:id/repos", ""},
|
|
|
|
{"GET", "/teams/:id/repos/:owner/:repo", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"PUT", "/teams/:id/repos/:owner/:repo", ""},
|
|
|
|
{"DELETE", "/teams/:id/repos/:owner/:repo", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/user/teams", ""},
|
2015-04-06 06:00:14 +02:00
|
|
|
|
2015-04-09 23:59:31 +02:00
|
|
|
// Pull Requests
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/pulls", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/pulls/:number", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/repos/:owner/:repo/pulls", ""},
|
|
|
|
//{"PATCH", "/repos/:owner/:repo/pulls/:number", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/pulls/:number/commits", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/pulls/:number/files", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/pulls/:number/merge", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"PUT", "/repos/:owner/:repo/pulls/:number/merge", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/pulls/:number/comments", ""},
|
|
|
|
//{"GET", "/repos/:owner/:repo/pulls/comments", ""},
|
|
|
|
//{"GET", "/repos/:owner/:repo/pulls/comments/:number", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"PUT", "/repos/:owner/:repo/pulls/:number/comments", ""},
|
|
|
|
//{"PATCH", "/repos/:owner/:repo/pulls/comments/:number", ""},
|
|
|
|
//{"DELETE", "/repos/:owner/:repo/pulls/comments/:number", ""},
|
2015-04-06 06:00:14 +02:00
|
|
|
|
2015-04-09 23:59:31 +02:00
|
|
|
// Repositories
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/user/repos", ""},
|
|
|
|
{"GET", "/users/:user/repos", ""},
|
|
|
|
{"GET", "/orgs/:org/repos", ""},
|
|
|
|
{"GET", "/repositories", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/user/repos", ""},
|
|
|
|
{"POST", "/orgs/:org/repos", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
//{"PATCH", "/repos/:owner/:repo", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/contributors", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/languages", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/teams", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/tags", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/branches", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/branches/:branch", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"DELETE", "/repos/:owner/:repo", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/collaborators", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/collaborators/:user", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"PUT", "/repos/:owner/:repo/collaborators/:user", ""},
|
|
|
|
{"DELETE", "/repos/:owner/:repo/collaborators/:user", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/comments", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/commits/:sha/comments", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/repos/:owner/:repo/commits/:sha/comments", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/comments/:id", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
//{"PATCH", "/repos/:owner/:repo/comments/:id", ""},
|
|
|
|
{"DELETE", "/repos/:owner/:repo/comments/:id", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/commits", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/commits/:sha", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/readme", ""},
|
|
|
|
//{"GET", "/repos/:owner/:repo/contents/*path", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
//{"PUT", "/repos/:owner/:repo/contents/*path", ""},
|
|
|
|
//{"DELETE", "/repos/:owner/:repo/contents/*path", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
//{"GET", "/repos/:owner/:repo/:archive_format/:ref", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/keys", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/keys/:id", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/repos/:owner/:repo/keys", ""},
|
|
|
|
//{"PATCH", "/repos/:owner/:repo/keys/:id", ""},
|
|
|
|
{"DELETE", "/repos/:owner/:repo/keys/:id", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/downloads", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/downloads/:id", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"DELETE", "/repos/:owner/:repo/downloads/:id", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/forks", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/repos/:owner/:repo/forks", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/hooks", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/hooks/:id", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/repos/:owner/:repo/hooks", ""},
|
|
|
|
//{"PATCH", "/repos/:owner/:repo/hooks/:id", ""},
|
|
|
|
{"POST", "/repos/:owner/:repo/hooks/:id/tests", ""},
|
|
|
|
{"DELETE", "/repos/:owner/:repo/hooks/:id", ""},
|
|
|
|
{"POST", "/repos/:owner/:repo/merges", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/releases", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/releases/:id", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/repos/:owner/:repo/releases", ""},
|
|
|
|
//{"PATCH", "/repos/:owner/:repo/releases/:id", ""},
|
|
|
|
{"DELETE", "/repos/:owner/:repo/releases/:id", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/repos/:owner/:repo/releases/:id/assets", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/stats/contributors", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/stats/commit_activity", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/stats/code_frequency", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/stats/participation", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/stats/punch_card", ""},
|
|
|
|
{"GET", "/repos/:owner/:repo/statuses/:ref", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/repos/:owner/:repo/statuses/:ref", ""},
|
2015-04-06 06:00:14 +02:00
|
|
|
|
2015-04-09 23:59:31 +02:00
|
|
|
// Search
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/search/repositories", ""},
|
|
|
|
{"GET", "/search/code", ""},
|
|
|
|
{"GET", "/search/issues", ""},
|
|
|
|
{"GET", "/search/users", ""},
|
|
|
|
{"GET", "/legacy/issues/search/:owner/:repository/:state/:keyword", ""},
|
|
|
|
{"GET", "/legacy/repos/search/:keyword", ""},
|
|
|
|
{"GET", "/legacy/user/search/:keyword", ""},
|
|
|
|
{"GET", "/legacy/user/email/:email", ""},
|
2015-04-06 06:00:14 +02:00
|
|
|
|
2015-04-09 23:59:31 +02:00
|
|
|
// Users
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/users/:user", ""},
|
|
|
|
{"GET", "/user", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
//{"PATCH", "/user", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/users", ""},
|
|
|
|
{"GET", "/user/emails", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/user/emails", ""},
|
|
|
|
{"DELETE", "/user/emails", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/users/:user/followers", ""},
|
|
|
|
{"GET", "/user/followers", ""},
|
|
|
|
{"GET", "/users/:user/following", ""},
|
|
|
|
{"GET", "/user/following", ""},
|
|
|
|
{"GET", "/user/following/:user", ""},
|
|
|
|
{"GET", "/users/:user/following/:target_user", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"PUT", "/user/following/:user", ""},
|
|
|
|
{"DELETE", "/user/following/:user", ""},
|
2016-11-12 19:42:25 +02:00
|
|
|
{"GET", "/users/:user/keys", ""},
|
|
|
|
{"GET", "/user/keys", ""},
|
|
|
|
{"GET", "/user/keys/:id", ""},
|
2016-01-09 19:44:18 +02:00
|
|
|
{"POST", "/user/keys", ""},
|
|
|
|
//{"PATCH", "/user/keys/:id", ""},
|
|
|
|
{"DELETE", "/user/keys/:id", ""},
|
2015-04-09 23:59:31 +02:00
|
|
|
}
|
2016-11-12 19:42:25 +02:00
|
|
|
|
|
|
|
parseAPI = []Route{
|
|
|
|
// Objects
|
|
|
|
{"POST", "/1/classes/:className", ""},
|
|
|
|
{"GET", "/1/classes/:className/:objectId", ""},
|
|
|
|
{"PUT", "/1/classes/:className/:objectId", ""},
|
|
|
|
{"GET", "/1/classes/:className", ""},
|
|
|
|
{"DELETE", "/1/classes/:className/:objectId", ""},
|
|
|
|
|
|
|
|
// Users
|
|
|
|
{"POST", "/1/users", ""},
|
|
|
|
{"GET", "/1/login", ""},
|
|
|
|
{"GET", "/1/users/:objectId", ""},
|
|
|
|
{"PUT", "/1/users/:objectId", ""},
|
|
|
|
{"GET", "/1/users", ""},
|
|
|
|
{"DELETE", "/1/users/:objectId", ""},
|
|
|
|
{"POST", "/1/requestPasswordReset", ""},
|
|
|
|
|
|
|
|
// Roles
|
|
|
|
{"POST", "/1/roles", ""},
|
|
|
|
{"GET", "/1/roles/:objectId", ""},
|
|
|
|
{"PUT", "/1/roles/:objectId", ""},
|
|
|
|
{"GET", "/1/roles", ""},
|
|
|
|
{"DELETE", "/1/roles/:objectId", ""},
|
|
|
|
|
|
|
|
// Files
|
|
|
|
{"POST", "/1/files/:fileName", ""},
|
|
|
|
|
|
|
|
// Analytics
|
|
|
|
{"POST", "/1/events/:eventName", ""},
|
|
|
|
|
|
|
|
// Push Notifications
|
|
|
|
{"POST", "/1/push", ""},
|
|
|
|
|
|
|
|
// Installations
|
|
|
|
{"POST", "/1/installations", ""},
|
|
|
|
{"GET", "/1/installations/:objectId", ""},
|
|
|
|
{"PUT", "/1/installations/:objectId", ""},
|
|
|
|
{"GET", "/1/installations", ""},
|
|
|
|
{"DELETE", "/1/installations/:objectId", ""},
|
|
|
|
|
|
|
|
// Cloud Functions
|
|
|
|
{"POST", "/1/functions", ""},
|
|
|
|
}
|
|
|
|
|
|
|
|
googlePlusAPI = []Route{
|
|
|
|
// People
|
|
|
|
{"GET", "/people/:userId", ""},
|
|
|
|
{"GET", "/people", ""},
|
|
|
|
{"GET", "/activities/:activityId/people/:collection", ""},
|
|
|
|
{"GET", "/people/:userId/people/:collection", ""},
|
|
|
|
{"GET", "/people/:userId/openIdConnect", ""},
|
|
|
|
|
|
|
|
// Activities
|
|
|
|
{"GET", "/people/:userId/activities/:collection", ""},
|
|
|
|
{"GET", "/activities/:activityId", ""},
|
|
|
|
{"GET", "/activities", ""},
|
|
|
|
|
|
|
|
// Comments
|
|
|
|
{"GET", "/activities/:activityId/comments", ""},
|
|
|
|
{"GET", "/comments/:commentId", ""},
|
|
|
|
|
|
|
|
// Moments
|
|
|
|
{"POST", "/people/:userId/moments/:collection", ""},
|
|
|
|
{"GET", "/people/:userId/moments/:collection", ""},
|
|
|
|
{"DELETE", "/moments/:id", ""},
|
|
|
|
}
|
2015-04-09 23:59:31 +02:00
|
|
|
)
|
2015-04-06 05:08:52 +02:00
|
|
|
|
2015-03-19 08:51:32 +02:00
|
|
|
func TestRouterStatic(t *testing.T) {
|
2015-06-04 00:18:27 +02:00
|
|
|
e := New()
|
|
|
|
r := e.router
|
2015-04-12 22:04:41 +02:00
|
|
|
path := "/folders/a/files/echo.gif"
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, path, func(c Context) error {
|
2015-05-31 00:20:36 +02:00
|
|
|
c.Set("path", path)
|
2015-04-19 01:47:48 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-10-11 02:31:26 +02:00
|
|
|
c := e.NewContext(nil, nil).(*context)
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, path, c)
|
2016-04-09 23:00:23 +02:00
|
|
|
c.handler(c)
|
2016-02-15 18:11:29 +02:00
|
|
|
assert.Equal(t, path, c.Get("path"))
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
|
|
|
|
2015-03-19 08:51:32 +02:00
|
|
|
func TestRouterParam(t *testing.T) {
|
2015-06-04 00:18:27 +02:00
|
|
|
e := New()
|
|
|
|
r := e.router
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/users/:id", func(c Context) error {
|
2015-04-19 01:47:48 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-10-11 02:31:26 +02:00
|
|
|
c := e.NewContext(nil, nil).(*context)
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/users/1", c)
|
2016-10-11 03:18:09 +02:00
|
|
|
assert.Equal(t, "1", c.Param("id"))
|
2015-04-04 19:44:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRouterTwoParam(t *testing.T) {
|
2015-06-04 00:18:27 +02:00
|
|
|
e := New()
|
|
|
|
r := e.router
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/users/:uid/files/:fid", func(Context) error {
|
2015-04-19 01:47:48 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-10-11 02:31:26 +02:00
|
|
|
c := e.NewContext(nil, nil).(*context)
|
2015-04-24 16:44:30 +02:00
|
|
|
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/users/1/files/1", c)
|
2016-10-11 03:18:09 +02:00
|
|
|
assert.Equal(t, "1", c.Param("uid"))
|
|
|
|
assert.Equal(t, "1", c.Param("fid"))
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
|
|
|
|
2016-03-07 09:24:51 +02:00
|
|
|
// Issue #378
|
|
|
|
func TestRouterParamWithSlash(t *testing.T) {
|
|
|
|
e := New()
|
|
|
|
r := e.router
|
|
|
|
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/a/:b/c/d/:e", func(c Context) error {
|
2016-03-07 09:24:51 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-03-07 09:24:51 +02:00
|
|
|
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/a/:b/c/:d/:f", func(c Context) error {
|
2016-03-07 09:24:51 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-03-07 09:24:51 +02:00
|
|
|
|
2016-10-11 02:31:26 +02:00
|
|
|
c := e.NewContext(nil, nil).(*context)
|
2016-03-07 09:24:51 +02:00
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
r.Find(GET, "/a/1/c/d/2/3", c)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-04-29 08:09:30 +02:00
|
|
|
func TestRouterMatchAny(t *testing.T) {
|
2015-06-04 00:18:27 +02:00
|
|
|
e := New()
|
|
|
|
r := e.router
|
2015-09-17 04:28:09 +02:00
|
|
|
|
|
|
|
// Routes
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/", func(Context) error {
|
2015-09-17 04:28:09 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/*", func(Context) error {
|
2015-09-17 04:28:09 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/users/*", func(Context) error {
|
2015-04-19 01:47:48 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-10-11 02:31:26 +02:00
|
|
|
c := e.NewContext(nil, nil).(*context)
|
2015-04-26 18:48:49 +02:00
|
|
|
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/", c)
|
2016-10-23 00:12:12 +02:00
|
|
|
assert.Equal(t, "", c.Param("*"))
|
2015-04-26 21:44:38 +02:00
|
|
|
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/download", c)
|
2016-10-11 03:36:48 +02:00
|
|
|
assert.Equal(t, "download", c.Param("*"))
|
2015-09-17 04:28:09 +02:00
|
|
|
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/users/joe", c)
|
2016-10-11 03:36:48 +02:00
|
|
|
assert.Equal(t, "joe", c.Param("*"))
|
2015-03-07 07:55:51 +02:00
|
|
|
}
|
|
|
|
|
2015-03-19 08:51:32 +02:00
|
|
|
func TestRouterMicroParam(t *testing.T) {
|
2015-06-04 00:18:27 +02:00
|
|
|
e := New()
|
|
|
|
r := e.router
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/:a/:b/:c", func(c Context) error {
|
2015-04-19 01:47:48 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-10-11 02:31:26 +02:00
|
|
|
c := e.NewContext(nil, nil).(*context)
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/1/2/3", c)
|
2016-10-11 03:18:09 +02:00
|
|
|
assert.Equal(t, "1", c.Param("a"))
|
|
|
|
assert.Equal(t, "2", c.Param("b"))
|
|
|
|
assert.Equal(t, "3", c.Param("c"))
|
2015-03-01 19:45:13 +02:00
|
|
|
}
|
2015-03-31 17:26:00 +02:00
|
|
|
|
2015-09-15 17:29:29 +02:00
|
|
|
func TestRouterMixParamMatchAny(t *testing.T) {
|
|
|
|
e := New()
|
|
|
|
r := e.router
|
|
|
|
|
|
|
|
// Route
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/users/:id/*", func(c Context) error {
|
2015-09-15 17:29:29 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-10-11 02:31:26 +02:00
|
|
|
c := e.NewContext(nil, nil).(*context)
|
2015-09-15 17:29:29 +02:00
|
|
|
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/users/joe/comments", c)
|
2016-04-09 23:00:23 +02:00
|
|
|
c.handler(c)
|
2016-10-11 03:18:09 +02:00
|
|
|
assert.Equal(t, "joe", c.Param("id"))
|
2015-09-15 17:29:29 +02:00
|
|
|
}
|
|
|
|
|
2015-04-13 22:12:30 +02:00
|
|
|
func TestRouterMultiRoute(t *testing.T) {
|
2015-06-04 00:18:27 +02:00
|
|
|
e := New()
|
|
|
|
r := e.router
|
2015-04-12 22:04:41 +02:00
|
|
|
|
2015-04-13 22:12:30 +02:00
|
|
|
// Routes
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/users", func(c Context) error {
|
2015-05-31 00:20:36 +02:00
|
|
|
c.Set("path", "/users")
|
2015-04-19 01:47:48 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/users/:id", func(c Context) error {
|
2015-04-19 01:47:48 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-10-11 02:31:26 +02:00
|
|
|
c := e.NewContext(nil, nil).(*context)
|
2015-04-13 22:12:30 +02:00
|
|
|
|
|
|
|
// Route > /users
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/users", c)
|
2016-04-09 23:00:23 +02:00
|
|
|
c.handler(c)
|
2016-02-15 18:11:29 +02:00
|
|
|
assert.Equal(t, "/users", c.Get("path"))
|
2015-04-12 22:04:41 +02:00
|
|
|
|
2015-05-10 07:06:13 +02:00
|
|
|
// Route > /users/:id
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/users/1", c)
|
2016-10-11 03:18:09 +02:00
|
|
|
assert.Equal(t, "1", c.Param("id"))
|
2015-04-12 22:04:41 +02:00
|
|
|
|
2015-04-13 22:12:30 +02:00
|
|
|
// Route > /user
|
2016-10-11 02:31:26 +02:00
|
|
|
c = e.NewContext(nil, nil).(*context)
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/user", c)
|
2016-04-09 23:00:23 +02:00
|
|
|
he := c.handler(c).(*HTTPError)
|
2016-03-11 17:53:54 +02:00
|
|
|
assert.Equal(t, http.StatusNotFound, he.Code)
|
2015-04-13 22:12:30 +02:00
|
|
|
}
|
|
|
|
|
2015-05-10 07:06:13 +02:00
|
|
|
func TestRouterPriority(t *testing.T) {
|
2015-06-04 00:18:27 +02:00
|
|
|
e := New()
|
|
|
|
r := e.router
|
2015-04-13 22:12:30 +02:00
|
|
|
|
|
|
|
// Routes
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/users", func(c Context) error {
|
2015-05-10 07:06:13 +02:00
|
|
|
c.Set("a", 1)
|
2015-04-19 01:47:48 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/users/new", func(c Context) error {
|
2015-05-10 07:06:13 +02:00
|
|
|
c.Set("b", 2)
|
2015-04-19 01:47:48 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/users/:id", func(c Context) error {
|
2015-05-10 07:06:13 +02:00
|
|
|
c.Set("c", 3)
|
2015-04-19 01:47:48 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/users/dew", func(c Context) error {
|
2015-05-10 07:06:13 +02:00
|
|
|
c.Set("d", 4)
|
2015-04-19 01:47:48 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/users/:id/files", func(c Context) error {
|
2015-05-10 07:06:13 +02:00
|
|
|
c.Set("e", 5)
|
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/users/newsee", func(c Context) error {
|
2015-05-10 07:06:13 +02:00
|
|
|
c.Set("f", 6)
|
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/users/*", func(c Context) error {
|
2015-05-10 07:06:13 +02:00
|
|
|
c.Set("g", 7)
|
2015-04-19 01:47:48 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-10-11 02:31:26 +02:00
|
|
|
c := e.NewContext(nil, nil).(*context)
|
2015-04-13 22:12:30 +02:00
|
|
|
|
|
|
|
// Route > /users
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/users", c)
|
2016-04-09 23:00:23 +02:00
|
|
|
c.handler(c)
|
2016-02-15 18:11:29 +02:00
|
|
|
assert.Equal(t, 1, c.Get("a"))
|
2015-04-13 22:12:30 +02:00
|
|
|
|
|
|
|
// Route > /users/new
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/users/new", c)
|
2016-04-09 23:00:23 +02:00
|
|
|
c.handler(c)
|
2016-02-15 18:11:29 +02:00
|
|
|
assert.Equal(t, 2, c.Get("b"))
|
2015-04-13 22:12:30 +02:00
|
|
|
|
2015-05-10 07:06:13 +02:00
|
|
|
// Route > /users/:id
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/users/1", c)
|
2016-04-09 23:00:23 +02:00
|
|
|
c.handler(c)
|
2016-02-15 18:11:29 +02:00
|
|
|
assert.Equal(t, 3, c.Get("c"))
|
2015-04-13 22:12:30 +02:00
|
|
|
|
2015-05-10 07:06:13 +02:00
|
|
|
// Route > /users/dew
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/users/dew", c)
|
2016-04-09 23:00:23 +02:00
|
|
|
c.handler(c)
|
2016-02-15 18:11:29 +02:00
|
|
|
assert.Equal(t, 4, c.Get("d"))
|
2015-04-13 22:12:30 +02:00
|
|
|
|
2015-05-10 07:06:13 +02:00
|
|
|
// Route > /users/:id/files
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/users/1/files", c)
|
2016-04-09 23:00:23 +02:00
|
|
|
c.handler(c)
|
2016-02-15 18:11:29 +02:00
|
|
|
assert.Equal(t, 5, c.Get("e"))
|
2015-04-13 22:12:30 +02:00
|
|
|
|
2015-05-10 07:06:13 +02:00
|
|
|
// Route > /users/:id
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/users/news", c)
|
2016-04-09 23:00:23 +02:00
|
|
|
c.handler(c)
|
2016-02-15 18:11:29 +02:00
|
|
|
assert.Equal(t, 3, c.Get("c"))
|
2015-04-13 22:12:30 +02:00
|
|
|
|
2015-05-10 07:06:13 +02:00
|
|
|
// Route > /users/*
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/users/joe/books", c)
|
2016-04-09 23:00:23 +02:00
|
|
|
c.handler(c)
|
2016-02-15 18:11:29 +02:00
|
|
|
assert.Equal(t, 7, c.Get("g"))
|
2016-10-11 03:36:48 +02:00
|
|
|
assert.Equal(t, "joe/books", c.Param("*"))
|
2015-04-11 22:52:40 +02:00
|
|
|
}
|
|
|
|
|
2016-03-04 08:06:47 +02:00
|
|
|
// Issue #372
|
|
|
|
func TestRouterPriorityNotFound(t *testing.T) {
|
|
|
|
e := New()
|
|
|
|
r := e.router
|
2016-10-11 02:31:26 +02:00
|
|
|
c := e.NewContext(nil, nil).(*context)
|
2016-03-04 08:06:47 +02:00
|
|
|
|
|
|
|
// Add
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/a/foo", func(c Context) error {
|
2016-03-04 08:06:47 +02:00
|
|
|
c.Set("a", 1)
|
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/a/bar", func(c Context) error {
|
2016-03-04 08:06:47 +02:00
|
|
|
c.Set("b", 2)
|
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-03-04 08:06:47 +02:00
|
|
|
|
|
|
|
// Find
|
|
|
|
r.Find(GET, "/a/foo", c)
|
2016-04-09 23:00:23 +02:00
|
|
|
c.handler(c)
|
2016-03-04 08:06:47 +02:00
|
|
|
assert.Equal(t, 1, c.Get("a"))
|
|
|
|
|
|
|
|
r.Find(GET, "/a/bar", c)
|
2016-04-09 23:00:23 +02:00
|
|
|
c.handler(c)
|
2016-03-04 08:06:47 +02:00
|
|
|
assert.Equal(t, 2, c.Get("b"))
|
|
|
|
|
2016-10-11 02:31:26 +02:00
|
|
|
c = e.NewContext(nil, nil).(*context)
|
2016-03-04 08:06:47 +02:00
|
|
|
r.Find(GET, "/abc/def", c)
|
2016-04-09 23:00:23 +02:00
|
|
|
he := c.handler(c).(*HTTPError)
|
2016-03-11 17:53:54 +02:00
|
|
|
assert.Equal(t, http.StatusNotFound, he.Code)
|
2016-03-04 08:06:47 +02:00
|
|
|
}
|
|
|
|
|
2015-04-24 16:44:30 +02:00
|
|
|
func TestRouterParamNames(t *testing.T) {
|
2015-06-04 00:18:27 +02:00
|
|
|
e := New()
|
|
|
|
r := e.router
|
2015-04-24 16:44:30 +02:00
|
|
|
|
|
|
|
// Routes
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/users", func(c Context) error {
|
2015-05-31 00:20:36 +02:00
|
|
|
c.Set("path", "/users")
|
2015-04-24 16:44:30 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/users/:id", func(c Context) error {
|
2015-04-24 16:44:30 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(GET, "/users/:uid/files/:fid", func(c Context) error {
|
2015-04-24 16:44:30 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-10-11 02:31:26 +02:00
|
|
|
c := e.NewContext(nil, nil).(*context)
|
2015-04-24 16:44:30 +02:00
|
|
|
|
|
|
|
// Route > /users
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/users", c)
|
2016-04-09 23:00:23 +02:00
|
|
|
c.handler(c)
|
2016-02-15 18:11:29 +02:00
|
|
|
assert.Equal(t, "/users", c.Get("path"))
|
2015-04-24 16:44:30 +02:00
|
|
|
|
2015-05-10 07:06:13 +02:00
|
|
|
// Route > /users/:id
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/users/1", c)
|
2016-04-17 00:53:27 +02:00
|
|
|
assert.Equal(t, "id", c.pnames[0])
|
2016-10-11 03:18:09 +02:00
|
|
|
assert.Equal(t, "1", c.Param("id"))
|
2015-04-24 16:44:30 +02:00
|
|
|
|
2015-05-10 07:06:13 +02:00
|
|
|
// Route > /users/:uid/files/:fid
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(GET, "/users/1/files/1", c)
|
2016-04-17 00:53:27 +02:00
|
|
|
assert.Equal(t, "uid", c.pnames[0])
|
2016-10-11 03:18:09 +02:00
|
|
|
assert.Equal(t, "1", c.Param("uid"))
|
2016-04-17 00:53:27 +02:00
|
|
|
assert.Equal(t, "fid", c.pnames[1])
|
2016-10-11 03:18:09 +02:00
|
|
|
assert.Equal(t, "1", c.Param("fid"))
|
2015-04-24 16:44:30 +02:00
|
|
|
}
|
|
|
|
|
2016-10-14 23:52:40 +02:00
|
|
|
// Issue #623
|
|
|
|
func TestRouterStaticDynamicConflict(t *testing.T) {
|
|
|
|
e := New()
|
|
|
|
r := e.router
|
|
|
|
c := e.NewContext(nil, nil)
|
|
|
|
|
|
|
|
r.Add(GET, "/dictionary/skills", func(c Context) error {
|
|
|
|
c.Set("a", 1)
|
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-10-14 23:52:40 +02:00
|
|
|
r.Add(GET, "/dictionary/:name", func(c Context) error {
|
|
|
|
c.Set("b", 2)
|
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-10-14 23:52:40 +02:00
|
|
|
r.Add(GET, "/server", func(c Context) error {
|
|
|
|
c.Set("c", 3)
|
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-10-14 23:52:40 +02:00
|
|
|
|
|
|
|
r.Find(GET, "/dictionary/skills", c)
|
|
|
|
c.Handler()(c)
|
|
|
|
assert.Equal(t, 1, c.Get("a"))
|
|
|
|
c = e.NewContext(nil, nil)
|
|
|
|
r.Find(GET, "/dictionary/type", c)
|
|
|
|
c.Handler()(c)
|
|
|
|
assert.Equal(t, 2, c.Get("b"))
|
|
|
|
c = e.NewContext(nil, nil)
|
|
|
|
r.Find(GET, "/server", c)
|
|
|
|
c.Handler()(c)
|
|
|
|
assert.Equal(t, 3, c.Get("c"))
|
|
|
|
}
|
|
|
|
|
2016-11-16 06:09:52 +02:00
|
|
|
func testRouterAPI(t *testing.T, api []Route) {
|
2015-06-04 00:18:27 +02:00
|
|
|
e := New()
|
|
|
|
r := e.router
|
|
|
|
|
2016-11-16 06:09:52 +02:00
|
|
|
for _, route := range api {
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(route.Method, route.Path, func(c Context) error {
|
2015-04-19 01:47:48 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2015-06-04 00:18:27 +02:00
|
|
|
}
|
2016-10-11 02:31:26 +02:00
|
|
|
c := e.NewContext(nil, nil).(*context)
|
2016-11-16 06:09:52 +02:00
|
|
|
for _, route := range api {
|
2016-02-15 18:11:29 +02:00
|
|
|
r.Find(route.Method, route.Path, c)
|
2016-11-16 06:09:52 +02:00
|
|
|
tokens := strings.Split(route.Path[1:], "/")
|
|
|
|
for _, token := range tokens {
|
|
|
|
if token[0] == ':' {
|
|
|
|
assert.Equal(t, c.Param(token[1:]), token)
|
2015-06-06 00:08:32 +02:00
|
|
|
}
|
2015-04-06 06:00:14 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-06 05:08:52 +02:00
|
|
|
}
|
|
|
|
|
2016-11-16 06:09:52 +02:00
|
|
|
func TestRouterGitHubAPI(t *testing.T) {
|
|
|
|
testRouterAPI(t, gitHubAPI)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Issue #729
|
|
|
|
func TestRouterParamAlias(t *testing.T) {
|
|
|
|
api := []Route{
|
|
|
|
{GET, "/users/:userID/following", ""},
|
|
|
|
{GET, "/users/:userID/followedBy", ""},
|
|
|
|
{GET, "/users/:userID/follow", ""},
|
|
|
|
}
|
|
|
|
testRouterAPI(t, api)
|
|
|
|
}
|
|
|
|
|
|
|
|
func benchmarkRouterRoutes(b *testing.B, routes []Route) {
|
2016-03-18 06:49:06 +02:00
|
|
|
e := New()
|
|
|
|
r := e.router
|
2016-03-18 17:47:03 +02:00
|
|
|
b.ReportAllocs()
|
2016-03-18 06:49:06 +02:00
|
|
|
|
|
|
|
// Add routes
|
2016-11-12 19:42:25 +02:00
|
|
|
for _, route := range routes {
|
2016-04-02 23:19:39 +02:00
|
|
|
r.Add(route.Method, route.Path, func(c Context) error {
|
2016-03-18 06:49:06 +02:00
|
|
|
return nil
|
2016-10-22 05:36:49 +02:00
|
|
|
})
|
2016-03-18 06:49:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find routes
|
|
|
|
for i := 0; i < b.N; i++ {
|
2016-11-12 19:42:25 +02:00
|
|
|
for _, route := range gitHubAPI {
|
|
|
|
c := e.pool.Get().(*context)
|
2016-03-18 06:49:06 +02:00
|
|
|
r.Find(route.Method, route.Path, c)
|
2016-11-12 19:42:25 +02:00
|
|
|
e.pool.Put(c)
|
2016-03-18 06:49:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 06:09:52 +02:00
|
|
|
func BenchmarkRouterStaticRoutes(b *testing.B) {
|
|
|
|
benchmarkRouterRoutes(b, staticRoutes)
|
2016-11-12 19:42:25 +02:00
|
|
|
}
|
|
|
|
|
2016-11-16 06:09:52 +02:00
|
|
|
func BenchmarkRouterGitHubAPI(b *testing.B) {
|
|
|
|
benchmarkRouterRoutes(b, gitHubAPI)
|
2016-11-12 19:42:25 +02:00
|
|
|
}
|
|
|
|
|
2016-11-16 06:09:52 +02:00
|
|
|
func BenchmarkRouterParseAPI(b *testing.B) {
|
|
|
|
benchmarkRouterRoutes(b, parseAPI)
|
2016-11-12 19:42:25 +02:00
|
|
|
}
|
|
|
|
|
2016-11-16 06:09:52 +02:00
|
|
|
func BenchmarkRouterGooglePlusAPI(b *testing.B) {
|
|
|
|
benchmarkRouterRoutes(b, googlePlusAPI)
|
2016-11-12 19:42:25 +02:00
|
|
|
}
|
|
|
|
|
2015-04-01 17:05:54 +02:00
|
|
|
func (n *node) printTree(pfx string, tail bool) {
|
|
|
|
p := prefix(tail, pfx, "└── ", "├── ")
|
2015-10-08 00:10:40 +02:00
|
|
|
fmt.Printf("%s%s, %p: type=%d, parent=%p, handler=%v\n", p, n.prefix, n, n.kind, n.parent, n.methodHandler)
|
2015-04-01 17:05:54 +02:00
|
|
|
|
2015-04-14 06:57:36 +02:00
|
|
|
children := n.children
|
|
|
|
l := len(children)
|
2015-04-01 17:05:54 +02:00
|
|
|
p = prefix(tail, pfx, " ", "│ ")
|
|
|
|
for i := 0; i < l-1; i++ {
|
2015-04-14 06:57:36 +02:00
|
|
|
children[i].printTree(p, false)
|
2015-04-01 17:05:54 +02:00
|
|
|
}
|
|
|
|
if l > 0 {
|
2015-04-14 06:57:36 +02:00
|
|
|
children[l-1].printTree(p, true)
|
2015-04-01 17:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func prefix(tail bool, p, on, off string) string {
|
|
|
|
if tail {
|
|
|
|
return fmt.Sprintf("%s%s", p, on)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s%s", p, off)
|
2015-03-31 17:26:00 +02:00
|
|
|
}
|