parent
352d69c71f
commit
d5f12ac6d7
@ -84,7 +84,7 @@ var (
|
|||||||
// Default returns the appropriate Binding instance based on the HTTP method
|
// Default returns the appropriate Binding instance based on the HTTP method
|
||||||
// and the content type.
|
// and the content type.
|
||||||
func Default(method, contentType string) Binding {
|
func Default(method, contentType string) Binding {
|
||||||
if method == "GET" {
|
if method == http.MethodGet {
|
||||||
return Form
|
return Form
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
gin.go
2
gin.go
@ -490,7 +490,7 @@ func redirectRequest(c *Context) {
|
|||||||
rURL := req.URL.String()
|
rURL := req.URL.String()
|
||||||
|
|
||||||
code := http.StatusMovedPermanently // Permanent redirect, request with GET method
|
code := http.StatusMovedPermanently // Permanent redirect, request with GET method
|
||||||
if req.Method != "GET" {
|
if req.Method != http.MethodGet {
|
||||||
code = http.StatusTemporaryRedirect
|
code = http.StatusTemporaryRedirect
|
||||||
}
|
}
|
||||||
debugPrint("redirecting request %d: %s --> %s", code, rPath, rURL)
|
debugPrint("redirecting request %d: %s --> %s", code, rPath, rURL)
|
||||||
|
@ -291,7 +291,7 @@ func TestConcurrentHandleContext(t *testing.T) {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
func testGetRequestHandler(t *testing.T, h http.Handler, url string) {
|
func testGetRequestHandler(t *testing.T, h http.Handler, url string) {
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@ -24,265 +24,265 @@ type route struct {
|
|||||||
// http://developer.github.com/v3/
|
// http://developer.github.com/v3/
|
||||||
var githubAPI = []route{
|
var githubAPI = []route{
|
||||||
// OAuth Authorizations
|
// OAuth Authorizations
|
||||||
{"GET", "/authorizations"},
|
{http.MethodGet, "/authorizations"},
|
||||||
{"GET", "/authorizations/:id"},
|
{http.MethodGet, "/authorizations/:id"},
|
||||||
{"POST", "/authorizations"},
|
{http.MethodPost, "/authorizations"},
|
||||||
//{"PUT", "/authorizations/clients/:client_id"},
|
//{http.MethodPut, "/authorizations/clients/:client_id"},
|
||||||
//{"PATCH", "/authorizations/:id"},
|
//{http.MethodPatch, "/authorizations/:id"},
|
||||||
{"DELETE", "/authorizations/:id"},
|
{http.MethodDelete, "/authorizations/:id"},
|
||||||
{"GET", "/applications/:client_id/tokens/:access_token"},
|
{http.MethodGet, "/applications/:client_id/tokens/:access_token"},
|
||||||
{"DELETE", "/applications/:client_id/tokens"},
|
{http.MethodDelete, "/applications/:client_id/tokens"},
|
||||||
{"DELETE", "/applications/:client_id/tokens/:access_token"},
|
{http.MethodDelete, "/applications/:client_id/tokens/:access_token"},
|
||||||
|
|
||||||
// Activity
|
// Activity
|
||||||
{"GET", "/events"},
|
{http.MethodGet, "/events"},
|
||||||
{"GET", "/repos/:owner/:repo/events"},
|
{http.MethodGet, "/repos/:owner/:repo/events"},
|
||||||
{"GET", "/networks/:owner/:repo/events"},
|
{http.MethodGet, "/networks/:owner/:repo/events"},
|
||||||
{"GET", "/orgs/:org/events"},
|
{http.MethodGet, "/orgs/:org/events"},
|
||||||
{"GET", "/users/:user/received_events"},
|
{http.MethodGet, "/users/:user/received_events"},
|
||||||
{"GET", "/users/:user/received_events/public"},
|
{http.MethodGet, "/users/:user/received_events/public"},
|
||||||
{"GET", "/users/:user/events"},
|
{http.MethodGet, "/users/:user/events"},
|
||||||
{"GET", "/users/:user/events/public"},
|
{http.MethodGet, "/users/:user/events/public"},
|
||||||
{"GET", "/users/:user/events/orgs/:org"},
|
{http.MethodGet, "/users/:user/events/orgs/:org"},
|
||||||
{"GET", "/feeds"},
|
{http.MethodGet, "/feeds"},
|
||||||
{"GET", "/notifications"},
|
{http.MethodGet, "/notifications"},
|
||||||
{"GET", "/repos/:owner/:repo/notifications"},
|
{http.MethodGet, "/repos/:owner/:repo/notifications"},
|
||||||
{"PUT", "/notifications"},
|
{http.MethodPut, "/notifications"},
|
||||||
{"PUT", "/repos/:owner/:repo/notifications"},
|
{http.MethodPut, "/repos/:owner/:repo/notifications"},
|
||||||
{"GET", "/notifications/threads/:id"},
|
{http.MethodGet, "/notifications/threads/:id"},
|
||||||
//{"PATCH", "/notifications/threads/:id"},
|
//{http.MethodPatch, "/notifications/threads/:id"},
|
||||||
{"GET", "/notifications/threads/:id/subscription"},
|
{http.MethodGet, "/notifications/threads/:id/subscription"},
|
||||||
{"PUT", "/notifications/threads/:id/subscription"},
|
{http.MethodPut, "/notifications/threads/:id/subscription"},
|
||||||
{"DELETE", "/notifications/threads/:id/subscription"},
|
{http.MethodDelete, "/notifications/threads/:id/subscription"},
|
||||||
{"GET", "/repos/:owner/:repo/stargazers"},
|
{http.MethodGet, "/repos/:owner/:repo/stargazers"},
|
||||||
{"GET", "/users/:user/starred"},
|
{http.MethodGet, "/users/:user/starred"},
|
||||||
{"GET", "/user/starred"},
|
{http.MethodGet, "/user/starred"},
|
||||||
{"GET", "/user/starred/:owner/:repo"},
|
{http.MethodGet, "/user/starred/:owner/:repo"},
|
||||||
{"PUT", "/user/starred/:owner/:repo"},
|
{http.MethodPut, "/user/starred/:owner/:repo"},
|
||||||
{"DELETE", "/user/starred/:owner/:repo"},
|
{http.MethodDelete, "/user/starred/:owner/:repo"},
|
||||||
{"GET", "/repos/:owner/:repo/subscribers"},
|
{http.MethodGet, "/repos/:owner/:repo/subscribers"},
|
||||||
{"GET", "/users/:user/subscriptions"},
|
{http.MethodGet, "/users/:user/subscriptions"},
|
||||||
{"GET", "/user/subscriptions"},
|
{http.MethodGet, "/user/subscriptions"},
|
||||||
{"GET", "/repos/:owner/:repo/subscription"},
|
{http.MethodGet, "/repos/:owner/:repo/subscription"},
|
||||||
{"PUT", "/repos/:owner/:repo/subscription"},
|
{http.MethodPut, "/repos/:owner/:repo/subscription"},
|
||||||
{"DELETE", "/repos/:owner/:repo/subscription"},
|
{http.MethodDelete, "/repos/:owner/:repo/subscription"},
|
||||||
{"GET", "/user/subscriptions/:owner/:repo"},
|
{http.MethodGet, "/user/subscriptions/:owner/:repo"},
|
||||||
{"PUT", "/user/subscriptions/:owner/:repo"},
|
{http.MethodPut, "/user/subscriptions/:owner/:repo"},
|
||||||
{"DELETE", "/user/subscriptions/:owner/:repo"},
|
{http.MethodDelete, "/user/subscriptions/:owner/:repo"},
|
||||||
|
|
||||||
// Gists
|
// Gists
|
||||||
{"GET", "/users/:user/gists"},
|
{http.MethodGet, "/users/:user/gists"},
|
||||||
{"GET", "/gists"},
|
{http.MethodGet, "/gists"},
|
||||||
//{"GET", "/gists/public"},
|
//{http.MethodGet, "/gists/public"},
|
||||||
//{"GET", "/gists/starred"},
|
//{http.MethodGet, "/gists/starred"},
|
||||||
{"GET", "/gists/:id"},
|
{http.MethodGet, "/gists/:id"},
|
||||||
{"POST", "/gists"},
|
{http.MethodPost, "/gists"},
|
||||||
//{"PATCH", "/gists/:id"},
|
//{http.MethodPatch, "/gists/:id"},
|
||||||
{"PUT", "/gists/:id/star"},
|
{http.MethodPut, "/gists/:id/star"},
|
||||||
{"DELETE", "/gists/:id/star"},
|
{http.MethodDelete, "/gists/:id/star"},
|
||||||
{"GET", "/gists/:id/star"},
|
{http.MethodGet, "/gists/:id/star"},
|
||||||
{"POST", "/gists/:id/forks"},
|
{http.MethodPost, "/gists/:id/forks"},
|
||||||
{"DELETE", "/gists/:id"},
|
{http.MethodDelete, "/gists/:id"},
|
||||||
|
|
||||||
// Git Data
|
// Git Data
|
||||||
{"GET", "/repos/:owner/:repo/git/blobs/:sha"},
|
{http.MethodGet, "/repos/:owner/:repo/git/blobs/:sha"},
|
||||||
{"POST", "/repos/:owner/:repo/git/blobs"},
|
{http.MethodPost, "/repos/:owner/:repo/git/blobs"},
|
||||||
{"GET", "/repos/:owner/:repo/git/commits/:sha"},
|
{http.MethodGet, "/repos/:owner/:repo/git/commits/:sha"},
|
||||||
{"POST", "/repos/:owner/:repo/git/commits"},
|
{http.MethodPost, "/repos/:owner/:repo/git/commits"},
|
||||||
//{"GET", "/repos/:owner/:repo/git/refs/*ref"},
|
//{http.MethodGet, "/repos/:owner/:repo/git/refs/*ref"},
|
||||||
{"GET", "/repos/:owner/:repo/git/refs"},
|
{http.MethodGet, "/repos/:owner/:repo/git/refs"},
|
||||||
{"POST", "/repos/:owner/:repo/git/refs"},
|
{http.MethodPost, "/repos/:owner/:repo/git/refs"},
|
||||||
//{"PATCH", "/repos/:owner/:repo/git/refs/*ref"},
|
//{http.MethodPatch, "/repos/:owner/:repo/git/refs/*ref"},
|
||||||
//{"DELETE", "/repos/:owner/:repo/git/refs/*ref"},
|
//{http.MethodDelete, "/repos/:owner/:repo/git/refs/*ref"},
|
||||||
{"GET", "/repos/:owner/:repo/git/tags/:sha"},
|
{http.MethodGet, "/repos/:owner/:repo/git/tags/:sha"},
|
||||||
{"POST", "/repos/:owner/:repo/git/tags"},
|
{http.MethodPost, "/repos/:owner/:repo/git/tags"},
|
||||||
{"GET", "/repos/:owner/:repo/git/trees/:sha"},
|
{http.MethodGet, "/repos/:owner/:repo/git/trees/:sha"},
|
||||||
{"POST", "/repos/:owner/:repo/git/trees"},
|
{http.MethodPost, "/repos/:owner/:repo/git/trees"},
|
||||||
|
|
||||||
// Issues
|
// Issues
|
||||||
{"GET", "/issues"},
|
{http.MethodGet, "/issues"},
|
||||||
{"GET", "/user/issues"},
|
{http.MethodGet, "/user/issues"},
|
||||||
{"GET", "/orgs/:org/issues"},
|
{http.MethodGet, "/orgs/:org/issues"},
|
||||||
{"GET", "/repos/:owner/:repo/issues"},
|
{http.MethodGet, "/repos/:owner/:repo/issues"},
|
||||||
{"GET", "/repos/:owner/:repo/issues/:number"},
|
{http.MethodGet, "/repos/:owner/:repo/issues/:number"},
|
||||||
{"POST", "/repos/:owner/:repo/issues"},
|
{http.MethodPost, "/repos/:owner/:repo/issues"},
|
||||||
//{"PATCH", "/repos/:owner/:repo/issues/:number"},
|
//{http.MethodPatch, "/repos/:owner/:repo/issues/:number"},
|
||||||
{"GET", "/repos/:owner/:repo/assignees"},
|
{http.MethodGet, "/repos/:owner/:repo/assignees"},
|
||||||
{"GET", "/repos/:owner/:repo/assignees/:assignee"},
|
{http.MethodGet, "/repos/:owner/:repo/assignees/:assignee"},
|
||||||
{"GET", "/repos/:owner/:repo/issues/:number/comments"},
|
{http.MethodGet, "/repos/:owner/:repo/issues/:number/comments"},
|
||||||
//{"GET", "/repos/:owner/:repo/issues/comments"},
|
//{http.MethodGet, "/repos/:owner/:repo/issues/comments"},
|
||||||
//{"GET", "/repos/:owner/:repo/issues/comments/:id"},
|
//{http.MethodGet, "/repos/:owner/:repo/issues/comments/:id"},
|
||||||
{"POST", "/repos/:owner/:repo/issues/:number/comments"},
|
{http.MethodPost, "/repos/:owner/:repo/issues/:number/comments"},
|
||||||
//{"PATCH", "/repos/:owner/:repo/issues/comments/:id"},
|
//{http.MethodPatch, "/repos/:owner/:repo/issues/comments/:id"},
|
||||||
//{"DELETE", "/repos/:owner/:repo/issues/comments/:id"},
|
//{http.MethodDelete, "/repos/:owner/:repo/issues/comments/:id"},
|
||||||
{"GET", "/repos/:owner/:repo/issues/:number/events"},
|
{http.MethodGet, "/repos/:owner/:repo/issues/:number/events"},
|
||||||
//{"GET", "/repos/:owner/:repo/issues/events"},
|
//{http.MethodGet, "/repos/:owner/:repo/issues/events"},
|
||||||
//{"GET", "/repos/:owner/:repo/issues/events/:id"},
|
//{http.MethodGet, "/repos/:owner/:repo/issues/events/:id"},
|
||||||
{"GET", "/repos/:owner/:repo/labels"},
|
{http.MethodGet, "/repos/:owner/:repo/labels"},
|
||||||
{"GET", "/repos/:owner/:repo/labels/:name"},
|
{http.MethodGet, "/repos/:owner/:repo/labels/:name"},
|
||||||
{"POST", "/repos/:owner/:repo/labels"},
|
{http.MethodPost, "/repos/:owner/:repo/labels"},
|
||||||
//{"PATCH", "/repos/:owner/:repo/labels/:name"},
|
//{http.MethodPatch, "/repos/:owner/:repo/labels/:name"},
|
||||||
{"DELETE", "/repos/:owner/:repo/labels/:name"},
|
{http.MethodDelete, "/repos/:owner/:repo/labels/:name"},
|
||||||
{"GET", "/repos/:owner/:repo/issues/:number/labels"},
|
{http.MethodGet, "/repos/:owner/:repo/issues/:number/labels"},
|
||||||
{"POST", "/repos/:owner/:repo/issues/:number/labels"},
|
{http.MethodPost, "/repos/:owner/:repo/issues/:number/labels"},
|
||||||
{"DELETE", "/repos/:owner/:repo/issues/:number/labels/:name"},
|
{http.MethodDelete, "/repos/:owner/:repo/issues/:number/labels/:name"},
|
||||||
{"PUT", "/repos/:owner/:repo/issues/:number/labels"},
|
{http.MethodPut, "/repos/:owner/:repo/issues/:number/labels"},
|
||||||
{"DELETE", "/repos/:owner/:repo/issues/:number/labels"},
|
{http.MethodDelete, "/repos/:owner/:repo/issues/:number/labels"},
|
||||||
{"GET", "/repos/:owner/:repo/milestones/:number/labels"},
|
{http.MethodGet, "/repos/:owner/:repo/milestones/:number/labels"},
|
||||||
{"GET", "/repos/:owner/:repo/milestones"},
|
{http.MethodGet, "/repos/:owner/:repo/milestones"},
|
||||||
{"GET", "/repos/:owner/:repo/milestones/:number"},
|
{http.MethodGet, "/repos/:owner/:repo/milestones/:number"},
|
||||||
{"POST", "/repos/:owner/:repo/milestones"},
|
{http.MethodPost, "/repos/:owner/:repo/milestones"},
|
||||||
//{"PATCH", "/repos/:owner/:repo/milestones/:number"},
|
//{http.MethodPatch, "/repos/:owner/:repo/milestones/:number"},
|
||||||
{"DELETE", "/repos/:owner/:repo/milestones/:number"},
|
{http.MethodDelete, "/repos/:owner/:repo/milestones/:number"},
|
||||||
|
|
||||||
// Miscellaneous
|
// Miscellaneous
|
||||||
{"GET", "/emojis"},
|
{http.MethodGet, "/emojis"},
|
||||||
{"GET", "/gitignore/templates"},
|
{http.MethodGet, "/gitignore/templates"},
|
||||||
{"GET", "/gitignore/templates/:name"},
|
{http.MethodGet, "/gitignore/templates/:name"},
|
||||||
{"POST", "/markdown"},
|
{http.MethodPost, "/markdown"},
|
||||||
{"POST", "/markdown/raw"},
|
{http.MethodPost, "/markdown/raw"},
|
||||||
{"GET", "/meta"},
|
{http.MethodGet, "/meta"},
|
||||||
{"GET", "/rate_limit"},
|
{http.MethodGet, "/rate_limit"},
|
||||||
|
|
||||||
// Organizations
|
// Organizations
|
||||||
{"GET", "/users/:user/orgs"},
|
{http.MethodGet, "/users/:user/orgs"},
|
||||||
{"GET", "/user/orgs"},
|
{http.MethodGet, "/user/orgs"},
|
||||||
{"GET", "/orgs/:org"},
|
{http.MethodGet, "/orgs/:org"},
|
||||||
//{"PATCH", "/orgs/:org"},
|
//{http.MethodPatch, "/orgs/:org"},
|
||||||
{"GET", "/orgs/:org/members"},
|
{http.MethodGet, "/orgs/:org/members"},
|
||||||
{"GET", "/orgs/:org/members/:user"},
|
{http.MethodGet, "/orgs/:org/members/:user"},
|
||||||
{"DELETE", "/orgs/:org/members/:user"},
|
{http.MethodDelete, "/orgs/:org/members/:user"},
|
||||||
{"GET", "/orgs/:org/public_members"},
|
{http.MethodGet, "/orgs/:org/public_members"},
|
||||||
{"GET", "/orgs/:org/public_members/:user"},
|
{http.MethodGet, "/orgs/:org/public_members/:user"},
|
||||||
{"PUT", "/orgs/:org/public_members/:user"},
|
{http.MethodPut, "/orgs/:org/public_members/:user"},
|
||||||
{"DELETE", "/orgs/:org/public_members/:user"},
|
{http.MethodDelete, "/orgs/:org/public_members/:user"},
|
||||||
{"GET", "/orgs/:org/teams"},
|
{http.MethodGet, "/orgs/:org/teams"},
|
||||||
{"GET", "/teams/:id"},
|
{http.MethodGet, "/teams/:id"},
|
||||||
{"POST", "/orgs/:org/teams"},
|
{http.MethodPost, "/orgs/:org/teams"},
|
||||||
//{"PATCH", "/teams/:id"},
|
//{http.MethodPatch, "/teams/:id"},
|
||||||
{"DELETE", "/teams/:id"},
|
{http.MethodDelete, "/teams/:id"},
|
||||||
{"GET", "/teams/:id/members"},
|
{http.MethodGet, "/teams/:id/members"},
|
||||||
{"GET", "/teams/:id/members/:user"},
|
{http.MethodGet, "/teams/:id/members/:user"},
|
||||||
{"PUT", "/teams/:id/members/:user"},
|
{http.MethodPut, "/teams/:id/members/:user"},
|
||||||
{"DELETE", "/teams/:id/members/:user"},
|
{http.MethodDelete, "/teams/:id/members/:user"},
|
||||||
{"GET", "/teams/:id/repos"},
|
{http.MethodGet, "/teams/:id/repos"},
|
||||||
{"GET", "/teams/:id/repos/:owner/:repo"},
|
{http.MethodGet, "/teams/:id/repos/:owner/:repo"},
|
||||||
{"PUT", "/teams/:id/repos/:owner/:repo"},
|
{http.MethodPut, "/teams/:id/repos/:owner/:repo"},
|
||||||
{"DELETE", "/teams/:id/repos/:owner/:repo"},
|
{http.MethodDelete, "/teams/:id/repos/:owner/:repo"},
|
||||||
{"GET", "/user/teams"},
|
{http.MethodGet, "/user/teams"},
|
||||||
|
|
||||||
// Pull Requests
|
// Pull Requests
|
||||||
{"GET", "/repos/:owner/:repo/pulls"},
|
{http.MethodGet, "/repos/:owner/:repo/pulls"},
|
||||||
{"GET", "/repos/:owner/:repo/pulls/:number"},
|
{http.MethodGet, "/repos/:owner/:repo/pulls/:number"},
|
||||||
{"POST", "/repos/:owner/:repo/pulls"},
|
{http.MethodPost, "/repos/:owner/:repo/pulls"},
|
||||||
//{"PATCH", "/repos/:owner/:repo/pulls/:number"},
|
//{http.MethodPatch, "/repos/:owner/:repo/pulls/:number"},
|
||||||
{"GET", "/repos/:owner/:repo/pulls/:number/commits"},
|
{http.MethodGet, "/repos/:owner/:repo/pulls/:number/commits"},
|
||||||
{"GET", "/repos/:owner/:repo/pulls/:number/files"},
|
{http.MethodGet, "/repos/:owner/:repo/pulls/:number/files"},
|
||||||
{"GET", "/repos/:owner/:repo/pulls/:number/merge"},
|
{http.MethodGet, "/repos/:owner/:repo/pulls/:number/merge"},
|
||||||
{"PUT", "/repos/:owner/:repo/pulls/:number/merge"},
|
{http.MethodPut, "/repos/:owner/:repo/pulls/:number/merge"},
|
||||||
{"GET", "/repos/:owner/:repo/pulls/:number/comments"},
|
{http.MethodGet, "/repos/:owner/:repo/pulls/:number/comments"},
|
||||||
//{"GET", "/repos/:owner/:repo/pulls/comments"},
|
//{http.MethodGet, "/repos/:owner/:repo/pulls/comments"},
|
||||||
//{"GET", "/repos/:owner/:repo/pulls/comments/:number"},
|
//{http.MethodGet, "/repos/:owner/:repo/pulls/comments/:number"},
|
||||||
{"PUT", "/repos/:owner/:repo/pulls/:number/comments"},
|
{http.MethodPut, "/repos/:owner/:repo/pulls/:number/comments"},
|
||||||
//{"PATCH", "/repos/:owner/:repo/pulls/comments/:number"},
|
//{http.MethodPatch, "/repos/:owner/:repo/pulls/comments/:number"},
|
||||||
//{"DELETE", "/repos/:owner/:repo/pulls/comments/:number"},
|
//{http.MethodDelete, "/repos/:owner/:repo/pulls/comments/:number"},
|
||||||
|
|
||||||
// Repositories
|
// Repositories
|
||||||
{"GET", "/user/repos"},
|
{http.MethodGet, "/user/repos"},
|
||||||
{"GET", "/users/:user/repos"},
|
{http.MethodGet, "/users/:user/repos"},
|
||||||
{"GET", "/orgs/:org/repos"},
|
{http.MethodGet, "/orgs/:org/repos"},
|
||||||
{"GET", "/repositories"},
|
{http.MethodGet, "/repositories"},
|
||||||
{"POST", "/user/repos"},
|
{http.MethodPost, "/user/repos"},
|
||||||
{"POST", "/orgs/:org/repos"},
|
{http.MethodPost, "/orgs/:org/repos"},
|
||||||
{"GET", "/repos/:owner/:repo"},
|
{http.MethodGet, "/repos/:owner/:repo"},
|
||||||
//{"PATCH", "/repos/:owner/:repo"},
|
//{http.MethodPatch, "/repos/:owner/:repo"},
|
||||||
{"GET", "/repos/:owner/:repo/contributors"},
|
{http.MethodGet, "/repos/:owner/:repo/contributors"},
|
||||||
{"GET", "/repos/:owner/:repo/languages"},
|
{http.MethodGet, "/repos/:owner/:repo/languages"},
|
||||||
{"GET", "/repos/:owner/:repo/teams"},
|
{http.MethodGet, "/repos/:owner/:repo/teams"},
|
||||||
{"GET", "/repos/:owner/:repo/tags"},
|
{http.MethodGet, "/repos/:owner/:repo/tags"},
|
||||||
{"GET", "/repos/:owner/:repo/branches"},
|
{http.MethodGet, "/repos/:owner/:repo/branches"},
|
||||||
{"GET", "/repos/:owner/:repo/branches/:branch"},
|
{http.MethodGet, "/repos/:owner/:repo/branches/:branch"},
|
||||||
{"DELETE", "/repos/:owner/:repo"},
|
{http.MethodDelete, "/repos/:owner/:repo"},
|
||||||
{"GET", "/repos/:owner/:repo/collaborators"},
|
{http.MethodGet, "/repos/:owner/:repo/collaborators"},
|
||||||
{"GET", "/repos/:owner/:repo/collaborators/:user"},
|
{http.MethodGet, "/repos/:owner/:repo/collaborators/:user"},
|
||||||
{"PUT", "/repos/:owner/:repo/collaborators/:user"},
|
{http.MethodPut, "/repos/:owner/:repo/collaborators/:user"},
|
||||||
{"DELETE", "/repos/:owner/:repo/collaborators/:user"},
|
{http.MethodDelete, "/repos/:owner/:repo/collaborators/:user"},
|
||||||
{"GET", "/repos/:owner/:repo/comments"},
|
{http.MethodGet, "/repos/:owner/:repo/comments"},
|
||||||
{"GET", "/repos/:owner/:repo/commits/:sha/comments"},
|
{http.MethodGet, "/repos/:owner/:repo/commits/:sha/comments"},
|
||||||
{"POST", "/repos/:owner/:repo/commits/:sha/comments"},
|
{http.MethodPost, "/repos/:owner/:repo/commits/:sha/comments"},
|
||||||
{"GET", "/repos/:owner/:repo/comments/:id"},
|
{http.MethodGet, "/repos/:owner/:repo/comments/:id"},
|
||||||
//{"PATCH", "/repos/:owner/:repo/comments/:id"},
|
//{http.MethodPatch, "/repos/:owner/:repo/comments/:id"},
|
||||||
{"DELETE", "/repos/:owner/:repo/comments/:id"},
|
{http.MethodDelete, "/repos/:owner/:repo/comments/:id"},
|
||||||
{"GET", "/repos/:owner/:repo/commits"},
|
{http.MethodGet, "/repos/:owner/:repo/commits"},
|
||||||
{"GET", "/repos/:owner/:repo/commits/:sha"},
|
{http.MethodGet, "/repos/:owner/:repo/commits/:sha"},
|
||||||
{"GET", "/repos/:owner/:repo/readme"},
|
{http.MethodGet, "/repos/:owner/:repo/readme"},
|
||||||
//{"GET", "/repos/:owner/:repo/contents/*path"},
|
//{http.MethodGet, "/repos/:owner/:repo/contents/*path"},
|
||||||
//{"PUT", "/repos/:owner/:repo/contents/*path"},
|
//{http.MethodPut, "/repos/:owner/:repo/contents/*path"},
|
||||||
//{"DELETE", "/repos/:owner/:repo/contents/*path"},
|
//{http.MethodDelete, "/repos/:owner/:repo/contents/*path"},
|
||||||
//{"GET", "/repos/:owner/:repo/:archive_format/:ref"},
|
//{http.MethodGet, "/repos/:owner/:repo/:archive_format/:ref"},
|
||||||
{"GET", "/repos/:owner/:repo/keys"},
|
{http.MethodGet, "/repos/:owner/:repo/keys"},
|
||||||
{"GET", "/repos/:owner/:repo/keys/:id"},
|
{http.MethodGet, "/repos/:owner/:repo/keys/:id"},
|
||||||
{"POST", "/repos/:owner/:repo/keys"},
|
{http.MethodPost, "/repos/:owner/:repo/keys"},
|
||||||
//{"PATCH", "/repos/:owner/:repo/keys/:id"},
|
//{http.MethodPatch, "/repos/:owner/:repo/keys/:id"},
|
||||||
{"DELETE", "/repos/:owner/:repo/keys/:id"},
|
{http.MethodDelete, "/repos/:owner/:repo/keys/:id"},
|
||||||
{"GET", "/repos/:owner/:repo/downloads"},
|
{http.MethodGet, "/repos/:owner/:repo/downloads"},
|
||||||
{"GET", "/repos/:owner/:repo/downloads/:id"},
|
{http.MethodGet, "/repos/:owner/:repo/downloads/:id"},
|
||||||
{"DELETE", "/repos/:owner/:repo/downloads/:id"},
|
{http.MethodDelete, "/repos/:owner/:repo/downloads/:id"},
|
||||||
{"GET", "/repos/:owner/:repo/forks"},
|
{http.MethodGet, "/repos/:owner/:repo/forks"},
|
||||||
{"POST", "/repos/:owner/:repo/forks"},
|
{http.MethodPost, "/repos/:owner/:repo/forks"},
|
||||||
{"GET", "/repos/:owner/:repo/hooks"},
|
{http.MethodGet, "/repos/:owner/:repo/hooks"},
|
||||||
{"GET", "/repos/:owner/:repo/hooks/:id"},
|
{http.MethodGet, "/repos/:owner/:repo/hooks/:id"},
|
||||||
{"POST", "/repos/:owner/:repo/hooks"},
|
{http.MethodPost, "/repos/:owner/:repo/hooks"},
|
||||||
//{"PATCH", "/repos/:owner/:repo/hooks/:id"},
|
//{http.MethodPatch, "/repos/:owner/:repo/hooks/:id"},
|
||||||
{"POST", "/repos/:owner/:repo/hooks/:id/tests"},
|
{http.MethodPost, "/repos/:owner/:repo/hooks/:id/tests"},
|
||||||
{"DELETE", "/repos/:owner/:repo/hooks/:id"},
|
{http.MethodDelete, "/repos/:owner/:repo/hooks/:id"},
|
||||||
{"POST", "/repos/:owner/:repo/merges"},
|
{http.MethodPost, "/repos/:owner/:repo/merges"},
|
||||||
{"GET", "/repos/:owner/:repo/releases"},
|
{http.MethodGet, "/repos/:owner/:repo/releases"},
|
||||||
{"GET", "/repos/:owner/:repo/releases/:id"},
|
{http.MethodGet, "/repos/:owner/:repo/releases/:id"},
|
||||||
{"POST", "/repos/:owner/:repo/releases"},
|
{http.MethodPost, "/repos/:owner/:repo/releases"},
|
||||||
//{"PATCH", "/repos/:owner/:repo/releases/:id"},
|
//{http.MethodPatch, "/repos/:owner/:repo/releases/:id"},
|
||||||
{"DELETE", "/repos/:owner/:repo/releases/:id"},
|
{http.MethodDelete, "/repos/:owner/:repo/releases/:id"},
|
||||||
{"GET", "/repos/:owner/:repo/releases/:id/assets"},
|
{http.MethodGet, "/repos/:owner/:repo/releases/:id/assets"},
|
||||||
{"GET", "/repos/:owner/:repo/stats/contributors"},
|
{http.MethodGet, "/repos/:owner/:repo/stats/contributors"},
|
||||||
{"GET", "/repos/:owner/:repo/stats/commit_activity"},
|
{http.MethodGet, "/repos/:owner/:repo/stats/commit_activity"},
|
||||||
{"GET", "/repos/:owner/:repo/stats/code_frequency"},
|
{http.MethodGet, "/repos/:owner/:repo/stats/code_frequency"},
|
||||||
{"GET", "/repos/:owner/:repo/stats/participation"},
|
{http.MethodGet, "/repos/:owner/:repo/stats/participation"},
|
||||||
{"GET", "/repos/:owner/:repo/stats/punch_card"},
|
{http.MethodGet, "/repos/:owner/:repo/stats/punch_card"},
|
||||||
{"GET", "/repos/:owner/:repo/statuses/:ref"},
|
{http.MethodGet, "/repos/:owner/:repo/statuses/:ref"},
|
||||||
{"POST", "/repos/:owner/:repo/statuses/:ref"},
|
{http.MethodPost, "/repos/:owner/:repo/statuses/:ref"},
|
||||||
|
|
||||||
// Search
|
// Search
|
||||||
{"GET", "/search/repositories"},
|
{http.MethodGet, "/search/repositories"},
|
||||||
{"GET", "/search/code"},
|
{http.MethodGet, "/search/code"},
|
||||||
{"GET", "/search/issues"},
|
{http.MethodGet, "/search/issues"},
|
||||||
{"GET", "/search/users"},
|
{http.MethodGet, "/search/users"},
|
||||||
{"GET", "/legacy/issues/search/:owner/:repository/:state/:keyword"},
|
{http.MethodGet, "/legacy/issues/search/:owner/:repository/:state/:keyword"},
|
||||||
{"GET", "/legacy/repos/search/:keyword"},
|
{http.MethodGet, "/legacy/repos/search/:keyword"},
|
||||||
{"GET", "/legacy/user/search/:keyword"},
|
{http.MethodGet, "/legacy/user/search/:keyword"},
|
||||||
{"GET", "/legacy/user/email/:email"},
|
{http.MethodGet, "/legacy/user/email/:email"},
|
||||||
|
|
||||||
// Users
|
// Users
|
||||||
{"GET", "/users/:user"},
|
{http.MethodGet, "/users/:user"},
|
||||||
{"GET", "/user"},
|
{http.MethodGet, "/user"},
|
||||||
//{"PATCH", "/user"},
|
//{http.MethodPatch, "/user"},
|
||||||
{"GET", "/users"},
|
{http.MethodGet, "/users"},
|
||||||
{"GET", "/user/emails"},
|
{http.MethodGet, "/user/emails"},
|
||||||
{"POST", "/user/emails"},
|
{http.MethodPost, "/user/emails"},
|
||||||
{"DELETE", "/user/emails"},
|
{http.MethodDelete, "/user/emails"},
|
||||||
{"GET", "/users/:user/followers"},
|
{http.MethodGet, "/users/:user/followers"},
|
||||||
{"GET", "/user/followers"},
|
{http.MethodGet, "/user/followers"},
|
||||||
{"GET", "/users/:user/following"},
|
{http.MethodGet, "/users/:user/following"},
|
||||||
{"GET", "/user/following"},
|
{http.MethodGet, "/user/following"},
|
||||||
{"GET", "/user/following/:user"},
|
{http.MethodGet, "/user/following/:user"},
|
||||||
{"GET", "/users/:user/following/:target_user"},
|
{http.MethodGet, "/users/:user/following/:target_user"},
|
||||||
{"PUT", "/user/following/:user"},
|
{http.MethodPut, "/user/following/:user"},
|
||||||
{"DELETE", "/user/following/:user"},
|
{http.MethodDelete, "/user/following/:user"},
|
||||||
{"GET", "/users/:user/keys"},
|
{http.MethodGet, "/users/:user/keys"},
|
||||||
{"GET", "/user/keys"},
|
{http.MethodGet, "/user/keys"},
|
||||||
{"GET", "/user/keys/:id"},
|
{http.MethodGet, "/user/keys/:id"},
|
||||||
{"POST", "/user/keys"},
|
{http.MethodPost, "/user/keys"},
|
||||||
//{"PATCH", "/user/keys/:id"},
|
//{http.MethodPatch, "/user/keys/:id"},
|
||||||
{"DELETE", "/user/keys/:id"},
|
{http.MethodDelete, "/user/keys/:id"},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShouldBindUri(t *testing.T) {
|
func TestShouldBindUri(t *testing.T) {
|
||||||
@ -293,7 +293,7 @@ func TestShouldBindUri(t *testing.T) {
|
|||||||
Name string `uri:"name" binding:"required"`
|
Name string `uri:"name" binding:"required"`
|
||||||
Id string `uri:"id" binding:"required"`
|
Id string `uri:"id" binding:"required"`
|
||||||
}
|
}
|
||||||
router.Handle("GET", "/rest/:name/:id", func(c *Context) {
|
router.Handle(http.MethodGet, "/rest/:name/:id", func(c *Context) {
|
||||||
var person Person
|
var person Person
|
||||||
assert.NoError(t, c.ShouldBindUri(&person))
|
assert.NoError(t, c.ShouldBindUri(&person))
|
||||||
assert.True(t, "" != person.Name)
|
assert.True(t, "" != person.Name)
|
||||||
@ -302,7 +302,7 @@ func TestShouldBindUri(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
path, _ := exampleFromPath("/rest/:name/:id")
|
path, _ := exampleFromPath("/rest/:name/:id")
|
||||||
w := performRequest(router, "GET", path)
|
w := performRequest(router, http.MethodGet, path)
|
||||||
assert.Equal(t, "ShouldBindUri test OK", w.Body.String())
|
assert.Equal(t, "ShouldBindUri test OK", w.Body.String())
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
}
|
}
|
||||||
@ -315,7 +315,7 @@ func TestBindUri(t *testing.T) {
|
|||||||
Name string `uri:"name" binding:"required"`
|
Name string `uri:"name" binding:"required"`
|
||||||
Id string `uri:"id" binding:"required"`
|
Id string `uri:"id" binding:"required"`
|
||||||
}
|
}
|
||||||
router.Handle("GET", "/rest/:name/:id", func(c *Context) {
|
router.Handle(http.MethodGet, "/rest/:name/:id", func(c *Context) {
|
||||||
var person Person
|
var person Person
|
||||||
assert.NoError(t, c.BindUri(&person))
|
assert.NoError(t, c.BindUri(&person))
|
||||||
assert.True(t, "" != person.Name)
|
assert.True(t, "" != person.Name)
|
||||||
@ -324,7 +324,7 @@ func TestBindUri(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
path, _ := exampleFromPath("/rest/:name/:id")
|
path, _ := exampleFromPath("/rest/:name/:id")
|
||||||
w := performRequest(router, "GET", path)
|
w := performRequest(router, http.MethodGet, path)
|
||||||
assert.Equal(t, "BindUri test OK", w.Body.String())
|
assert.Equal(t, "BindUri test OK", w.Body.String())
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
}
|
}
|
||||||
@ -336,13 +336,13 @@ func TestBindUriError(t *testing.T) {
|
|||||||
type Member struct {
|
type Member struct {
|
||||||
Number string `uri:"num" binding:"required,uuid"`
|
Number string `uri:"num" binding:"required,uuid"`
|
||||||
}
|
}
|
||||||
router.Handle("GET", "/new/rest/:num", func(c *Context) {
|
router.Handle(http.MethodGet, "/new/rest/:num", func(c *Context) {
|
||||||
var m Member
|
var m Member
|
||||||
assert.Error(t, c.BindUri(&m))
|
assert.Error(t, c.BindUri(&m))
|
||||||
})
|
})
|
||||||
|
|
||||||
path1, _ := exampleFromPath("/new/rest/:num")
|
path1, _ := exampleFromPath("/new/rest/:num")
|
||||||
w1 := performRequest(router, "GET", path1)
|
w1 := performRequest(router, http.MethodGet, path1)
|
||||||
assert.Equal(t, http.StatusBadRequest, w1.Code)
|
assert.Equal(t, http.StatusBadRequest, w1.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,7 +358,7 @@ func TestRaceContextCopy(t *testing.T) {
|
|||||||
go readWriteKeys(c.Copy())
|
go readWriteKeys(c.Copy())
|
||||||
c.String(http.StatusOK, "run OK, no panics")
|
c.String(http.StatusOK, "run OK, no panics")
|
||||||
})
|
})
|
||||||
w := performRequest(router, "GET", "/test/copy/race")
|
w := performRequest(router, http.MethodGet, "/test/copy/race")
|
||||||
assert.Equal(t, "run OK, no panics", w.Body.String())
|
assert.Equal(t, "run OK, no panics", w.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,7 +438,7 @@ func exampleFromPath(path string) (string, Params) {
|
|||||||
func BenchmarkGithub(b *testing.B) {
|
func BenchmarkGithub(b *testing.B) {
|
||||||
router := New()
|
router := New()
|
||||||
githubConfigRouter(router)
|
githubConfigRouter(router)
|
||||||
runRequest(b, router, "GET", "/legacy/issues/search/:owner/:repository/:state/:keyword")
|
runRequest(b, router, http.MethodGet, "/legacy/issues/search/:owner/:repository/:state/:keyword")
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkParallelGithub(b *testing.B) {
|
func BenchmarkParallelGithub(b *testing.B) {
|
||||||
@ -446,7 +446,7 @@ func BenchmarkParallelGithub(b *testing.B) {
|
|||||||
router := New()
|
router := New()
|
||||||
githubConfigRouter(router)
|
githubConfigRouter(router)
|
||||||
|
|
||||||
req, _ := http.NewRequest("POST", "/repos/manucorporat/sse/git/blobs", nil)
|
req, _ := http.NewRequest(http.MethodPost, "/repos/manucorporat/sse/git/blobs", nil)
|
||||||
|
|
||||||
b.RunParallel(func(pb *testing.PB) {
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
// Each goroutine has its own bytes.Buffer.
|
// Each goroutine has its own bytes.Buffer.
|
||||||
@ -462,7 +462,7 @@ func BenchmarkParallelGithubDefault(b *testing.B) {
|
|||||||
router := New()
|
router := New()
|
||||||
githubConfigRouter(router)
|
githubConfigRouter(router)
|
||||||
|
|
||||||
req, _ := http.NewRequest("POST", "/repos/manucorporat/sse/git/blobs", nil)
|
req, _ := http.NewRequest(http.MethodPost, "/repos/manucorporat/sse/git/blobs", nil)
|
||||||
|
|
||||||
b.RunParallel(func(pb *testing.PB) {
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
// Each goroutine has its own bytes.Buffer.
|
// Each goroutine has its own bytes.Buffer.
|
||||||
|
14
logger.go
14
logger.go
@ -99,19 +99,19 @@ func (p *LogFormatterParams) MethodColor() string {
|
|||||||
method := p.Method
|
method := p.Method
|
||||||
|
|
||||||
switch method {
|
switch method {
|
||||||
case "GET":
|
case http.MethodGet:
|
||||||
return blue
|
return blue
|
||||||
case "POST":
|
case http.MethodPost:
|
||||||
return cyan
|
return cyan
|
||||||
case "PUT":
|
case http.MethodPut:
|
||||||
return yellow
|
return yellow
|
||||||
case "DELETE":
|
case http.MethodDelete:
|
||||||
return red
|
return red
|
||||||
case "PATCH":
|
case http.MethodPatch:
|
||||||
return green
|
return green
|
||||||
case "HEAD":
|
case http.MethodHead:
|
||||||
return magenta
|
return magenta
|
||||||
case "OPTIONS":
|
case http.MethodOptions:
|
||||||
return white
|
return white
|
||||||
default:
|
default:
|
||||||
return reset
|
return reset
|
||||||
|
@ -95,51 +95,51 @@ func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...Ha
|
|||||||
|
|
||||||
// POST is a shortcut for router.Handle("POST", path, handle).
|
// POST is a shortcut for router.Handle("POST", path, handle).
|
||||||
func (group *RouterGroup) POST(relativePath string, handlers ...HandlerFunc) IRoutes {
|
func (group *RouterGroup) POST(relativePath string, handlers ...HandlerFunc) IRoutes {
|
||||||
return group.handle("POST", relativePath, handlers)
|
return group.handle(http.MethodPost, relativePath, handlers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET is a shortcut for router.Handle("GET", path, handle).
|
// GET is a shortcut for router.Handle("GET", path, handle).
|
||||||
func (group *RouterGroup) GET(relativePath string, handlers ...HandlerFunc) IRoutes {
|
func (group *RouterGroup) GET(relativePath string, handlers ...HandlerFunc) IRoutes {
|
||||||
return group.handle("GET", relativePath, handlers)
|
return group.handle(http.MethodGet, relativePath, handlers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE is a shortcut for router.Handle("DELETE", path, handle).
|
// DELETE is a shortcut for router.Handle("DELETE", path, handle).
|
||||||
func (group *RouterGroup) DELETE(relativePath string, handlers ...HandlerFunc) IRoutes {
|
func (group *RouterGroup) DELETE(relativePath string, handlers ...HandlerFunc) IRoutes {
|
||||||
return group.handle("DELETE", relativePath, handlers)
|
return group.handle(http.MethodDelete, relativePath, handlers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PATCH is a shortcut for router.Handle("PATCH", path, handle).
|
// PATCH is a shortcut for router.Handle("PATCH", path, handle).
|
||||||
func (group *RouterGroup) PATCH(relativePath string, handlers ...HandlerFunc) IRoutes {
|
func (group *RouterGroup) PATCH(relativePath string, handlers ...HandlerFunc) IRoutes {
|
||||||
return group.handle("PATCH", relativePath, handlers)
|
return group.handle(http.MethodPatch, relativePath, handlers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT is a shortcut for router.Handle("PUT", path, handle).
|
// PUT is a shortcut for router.Handle("PUT", path, handle).
|
||||||
func (group *RouterGroup) PUT(relativePath string, handlers ...HandlerFunc) IRoutes {
|
func (group *RouterGroup) PUT(relativePath string, handlers ...HandlerFunc) IRoutes {
|
||||||
return group.handle("PUT", relativePath, handlers)
|
return group.handle(http.MethodPut, relativePath, handlers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OPTIONS is a shortcut for router.Handle("OPTIONS", path, handle).
|
// OPTIONS is a shortcut for router.Handle("OPTIONS", path, handle).
|
||||||
func (group *RouterGroup) OPTIONS(relativePath string, handlers ...HandlerFunc) IRoutes {
|
func (group *RouterGroup) OPTIONS(relativePath string, handlers ...HandlerFunc) IRoutes {
|
||||||
return group.handle("OPTIONS", relativePath, handlers)
|
return group.handle(http.MethodOptions, relativePath, handlers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HEAD is a shortcut for router.Handle("HEAD", path, handle).
|
// HEAD is a shortcut for router.Handle("HEAD", path, handle).
|
||||||
func (group *RouterGroup) HEAD(relativePath string, handlers ...HandlerFunc) IRoutes {
|
func (group *RouterGroup) HEAD(relativePath string, handlers ...HandlerFunc) IRoutes {
|
||||||
return group.handle("HEAD", relativePath, handlers)
|
return group.handle(http.MethodHead, relativePath, handlers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Any registers a route that matches all the HTTP methods.
|
// Any registers a route that matches all the HTTP methods.
|
||||||
// GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE.
|
// GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE.
|
||||||
func (group *RouterGroup) Any(relativePath string, handlers ...HandlerFunc) IRoutes {
|
func (group *RouterGroup) Any(relativePath string, handlers ...HandlerFunc) IRoutes {
|
||||||
group.handle("GET", relativePath, handlers)
|
group.handle(http.MethodGet, relativePath, handlers)
|
||||||
group.handle("POST", relativePath, handlers)
|
group.handle(http.MethodPost, relativePath, handlers)
|
||||||
group.handle("PUT", relativePath, handlers)
|
group.handle(http.MethodPut, relativePath, handlers)
|
||||||
group.handle("PATCH", relativePath, handlers)
|
group.handle(http.MethodPatch, relativePath, handlers)
|
||||||
group.handle("HEAD", relativePath, handlers)
|
group.handle(http.MethodHead, relativePath, handlers)
|
||||||
group.handle("OPTIONS", relativePath, handlers)
|
group.handle(http.MethodOptions, relativePath, handlers)
|
||||||
group.handle("DELETE", relativePath, handlers)
|
group.handle(http.MethodDelete, relativePath, handlers)
|
||||||
group.handle("CONNECT", relativePath, handlers)
|
group.handle(http.MethodConnect, relativePath, handlers)
|
||||||
group.handle("TRACE", relativePath, handlers)
|
group.handle(http.MethodTrace, relativePath, handlers)
|
||||||
return group.returnObj()
|
return group.returnObj()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,13 +33,13 @@ func TestRouterGroupBasic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRouterGroupBasicHandle(t *testing.T) {
|
func TestRouterGroupBasicHandle(t *testing.T) {
|
||||||
performRequestInGroup(t, "GET")
|
performRequestInGroup(t, http.MethodGet)
|
||||||
performRequestInGroup(t, "POST")
|
performRequestInGroup(t, http.MethodPost)
|
||||||
performRequestInGroup(t, "PUT")
|
performRequestInGroup(t, http.MethodPut)
|
||||||
performRequestInGroup(t, "PATCH")
|
performRequestInGroup(t, http.MethodPatch)
|
||||||
performRequestInGroup(t, "DELETE")
|
performRequestInGroup(t, http.MethodDelete)
|
||||||
performRequestInGroup(t, "HEAD")
|
performRequestInGroup(t, http.MethodHead)
|
||||||
performRequestInGroup(t, "OPTIONS")
|
performRequestInGroup(t, http.MethodOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
func performRequestInGroup(t *testing.T, method string) {
|
func performRequestInGroup(t *testing.T, method string) {
|
||||||
@ -55,25 +55,25 @@ func performRequestInGroup(t *testing.T, method string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch method {
|
switch method {
|
||||||
case "GET":
|
case http.MethodGet:
|
||||||
v1.GET("/test", handler)
|
v1.GET("/test", handler)
|
||||||
login.GET("/test", handler)
|
login.GET("/test", handler)
|
||||||
case "POST":
|
case http.MethodPost:
|
||||||
v1.POST("/test", handler)
|
v1.POST("/test", handler)
|
||||||
login.POST("/test", handler)
|
login.POST("/test", handler)
|
||||||
case "PUT":
|
case http.MethodPut:
|
||||||
v1.PUT("/test", handler)
|
v1.PUT("/test", handler)
|
||||||
login.PUT("/test", handler)
|
login.PUT("/test", handler)
|
||||||
case "PATCH":
|
case http.MethodPatch:
|
||||||
v1.PATCH("/test", handler)
|
v1.PATCH("/test", handler)
|
||||||
login.PATCH("/test", handler)
|
login.PATCH("/test", handler)
|
||||||
case "DELETE":
|
case http.MethodDelete:
|
||||||
v1.DELETE("/test", handler)
|
v1.DELETE("/test", handler)
|
||||||
login.DELETE("/test", handler)
|
login.DELETE("/test", handler)
|
||||||
case "HEAD":
|
case http.MethodHead:
|
||||||
v1.HEAD("/test", handler)
|
v1.HEAD("/test", handler)
|
||||||
login.HEAD("/test", handler)
|
login.HEAD("/test", handler)
|
||||||
case "OPTIONS":
|
case http.MethodOptions:
|
||||||
v1.OPTIONS("/test", handler)
|
v1.OPTIONS("/test", handler)
|
||||||
login.OPTIONS("/test", handler)
|
login.OPTIONS("/test", handler)
|
||||||
default:
|
default:
|
||||||
@ -128,7 +128,7 @@ func TestRouterGroupTooManyHandlers(t *testing.T) {
|
|||||||
func TestRouterGroupBadMethod(t *testing.T) {
|
func TestRouterGroupBadMethod(t *testing.T) {
|
||||||
router := New()
|
router := New()
|
||||||
assert.Panics(t, func() {
|
assert.Panics(t, func() {
|
||||||
router.Handle("get", "/")
|
router.Handle(http.MethodGet, "/")
|
||||||
})
|
})
|
||||||
assert.Panics(t, func() {
|
assert.Panics(t, func() {
|
||||||
router.Handle(" GET", "/")
|
router.Handle(" GET", "/")
|
||||||
@ -162,7 +162,7 @@ func testRoutesInterface(t *testing.T, r IRoutes) {
|
|||||||
handler := func(c *Context) {}
|
handler := func(c *Context) {}
|
||||||
assert.Equal(t, r, r.Use(handler))
|
assert.Equal(t, r, r.Use(handler))
|
||||||
|
|
||||||
assert.Equal(t, r, r.Handle("GET", "/handler", handler))
|
assert.Equal(t, r, r.Handle(http.MethodGet, "/handler", handler))
|
||||||
assert.Equal(t, r, r.Any("/any", handler))
|
assert.Equal(t, r, r.Any("/any", handler))
|
||||||
assert.Equal(t, r, r.GET("/", handler))
|
assert.Equal(t, r, r.GET("/", handler))
|
||||||
assert.Equal(t, r, r.POST("/", handler))
|
assert.Equal(t, r, r.POST("/", handler))
|
||||||
|
156
routes_test.go
156
routes_test.go
@ -70,10 +70,10 @@ func testRouteNotOK2(method string, t *testing.T) {
|
|||||||
router := New()
|
router := New()
|
||||||
router.HandleMethodNotAllowed = true
|
router.HandleMethodNotAllowed = true
|
||||||
var methodRoute string
|
var methodRoute string
|
||||||
if method == "POST" {
|
if method == http.MethodPost {
|
||||||
methodRoute = "GET"
|
methodRoute = http.MethodGet
|
||||||
} else {
|
} else {
|
||||||
methodRoute = "POST"
|
methodRoute = http.MethodPost
|
||||||
}
|
}
|
||||||
router.Handle(methodRoute, "/test", func(c *Context) {
|
router.Handle(methodRoute, "/test", func(c *Context) {
|
||||||
passed = true
|
passed = true
|
||||||
@ -99,46 +99,46 @@ func TestRouterMethod(t *testing.T) {
|
|||||||
c.String(http.StatusOK, "sup3")
|
c.String(http.StatusOK, "sup3")
|
||||||
})
|
})
|
||||||
|
|
||||||
w := performRequest(router, "PUT", "/hey")
|
w := performRequest(router, http.MethodPut, "/hey")
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
assert.Equal(t, "called", w.Body.String())
|
assert.Equal(t, "called", w.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRouterGroupRouteOK(t *testing.T) {
|
func TestRouterGroupRouteOK(t *testing.T) {
|
||||||
testRouteOK("GET", t)
|
testRouteOK(http.MethodGet, t)
|
||||||
testRouteOK("POST", t)
|
testRouteOK(http.MethodPost, t)
|
||||||
testRouteOK("PUT", t)
|
testRouteOK(http.MethodPut, t)
|
||||||
testRouteOK("PATCH", t)
|
testRouteOK(http.MethodPatch, t)
|
||||||
testRouteOK("HEAD", t)
|
testRouteOK(http.MethodHead, t)
|
||||||
testRouteOK("OPTIONS", t)
|
testRouteOK(http.MethodOptions, t)
|
||||||
testRouteOK("DELETE", t)
|
testRouteOK(http.MethodDelete, t)
|
||||||
testRouteOK("CONNECT", t)
|
testRouteOK(http.MethodConnect, t)
|
||||||
testRouteOK("TRACE", t)
|
testRouteOK(http.MethodTrace, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRouteNotOK(t *testing.T) {
|
func TestRouteNotOK(t *testing.T) {
|
||||||
testRouteNotOK("GET", t)
|
testRouteNotOK(http.MethodGet, t)
|
||||||
testRouteNotOK("POST", t)
|
testRouteNotOK(http.MethodPost, t)
|
||||||
testRouteNotOK("PUT", t)
|
testRouteNotOK(http.MethodPut, t)
|
||||||
testRouteNotOK("PATCH", t)
|
testRouteNotOK(http.MethodPatch, t)
|
||||||
testRouteNotOK("HEAD", t)
|
testRouteNotOK(http.MethodHead, t)
|
||||||
testRouteNotOK("OPTIONS", t)
|
testRouteNotOK(http.MethodOptions, t)
|
||||||
testRouteNotOK("DELETE", t)
|
testRouteNotOK(http.MethodDelete, t)
|
||||||
testRouteNotOK("CONNECT", t)
|
testRouteNotOK(http.MethodConnect, t)
|
||||||
testRouteNotOK("TRACE", t)
|
testRouteNotOK(http.MethodTrace, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRouteNotOK2(t *testing.T) {
|
func TestRouteNotOK2(t *testing.T) {
|
||||||
testRouteNotOK2("GET", t)
|
testRouteNotOK2(http.MethodGet, t)
|
||||||
testRouteNotOK2("POST", t)
|
testRouteNotOK2(http.MethodPost, t)
|
||||||
testRouteNotOK2("PUT", t)
|
testRouteNotOK2(http.MethodPut, t)
|
||||||
testRouteNotOK2("PATCH", t)
|
testRouteNotOK2(http.MethodPatch, t)
|
||||||
testRouteNotOK2("HEAD", t)
|
testRouteNotOK2(http.MethodHead, t)
|
||||||
testRouteNotOK2("OPTIONS", t)
|
testRouteNotOK2(http.MethodOptions, t)
|
||||||
testRouteNotOK2("DELETE", t)
|
testRouteNotOK2(http.MethodDelete, t)
|
||||||
testRouteNotOK2("CONNECT", t)
|
testRouteNotOK2(http.MethodConnect, t)
|
||||||
testRouteNotOK2("TRACE", t)
|
testRouteNotOK2(http.MethodTrace, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRouteRedirectTrailingSlash(t *testing.T) {
|
func TestRouteRedirectTrailingSlash(t *testing.T) {
|
||||||
@ -150,50 +150,50 @@ func TestRouteRedirectTrailingSlash(t *testing.T) {
|
|||||||
router.POST("/path3", func(c *Context) {})
|
router.POST("/path3", func(c *Context) {})
|
||||||
router.PUT("/path4/", func(c *Context) {})
|
router.PUT("/path4/", func(c *Context) {})
|
||||||
|
|
||||||
w := performRequest(router, "GET", "/path/")
|
w := performRequest(router, http.MethodGet, "/path/")
|
||||||
assert.Equal(t, "/path", w.Header().Get("Location"))
|
assert.Equal(t, "/path", w.Header().Get("Location"))
|
||||||
assert.Equal(t, http.StatusMovedPermanently, w.Code)
|
assert.Equal(t, http.StatusMovedPermanently, w.Code)
|
||||||
|
|
||||||
w = performRequest(router, "GET", "/path2")
|
w = performRequest(router, http.MethodGet, "/path2")
|
||||||
assert.Equal(t, "/path2/", w.Header().Get("Location"))
|
assert.Equal(t, "/path2/", w.Header().Get("Location"))
|
||||||
assert.Equal(t, http.StatusMovedPermanently, w.Code)
|
assert.Equal(t, http.StatusMovedPermanently, w.Code)
|
||||||
|
|
||||||
w = performRequest(router, "POST", "/path3/")
|
w = performRequest(router, http.MethodPost, "/path3/")
|
||||||
assert.Equal(t, "/path3", w.Header().Get("Location"))
|
assert.Equal(t, "/path3", w.Header().Get("Location"))
|
||||||
assert.Equal(t, http.StatusTemporaryRedirect, w.Code)
|
assert.Equal(t, http.StatusTemporaryRedirect, w.Code)
|
||||||
|
|
||||||
w = performRequest(router, "PUT", "/path4")
|
w = performRequest(router, http.MethodPut, "/path4")
|
||||||
assert.Equal(t, "/path4/", w.Header().Get("Location"))
|
assert.Equal(t, "/path4/", w.Header().Get("Location"))
|
||||||
assert.Equal(t, http.StatusTemporaryRedirect, w.Code)
|
assert.Equal(t, http.StatusTemporaryRedirect, w.Code)
|
||||||
|
|
||||||
w = performRequest(router, "GET", "/path")
|
w = performRequest(router, http.MethodGet, "/path")
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
|
|
||||||
w = performRequest(router, "GET", "/path2/")
|
w = performRequest(router, http.MethodGet, "/path2/")
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
|
|
||||||
w = performRequest(router, "POST", "/path3")
|
w = performRequest(router, http.MethodPost, "/path3")
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
|
|
||||||
w = performRequest(router, "PUT", "/path4/")
|
w = performRequest(router, http.MethodPut, "/path4/")
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
|
|
||||||
w = performRequest(router, "GET", "/path2", header{Key: "X-Forwarded-Prefix", Value: "/api"})
|
w = performRequest(router, http.MethodGet, "/path2", header{Key: "X-Forwarded-Prefix", Value: "/api"})
|
||||||
assert.Equal(t, "/api/path2/", w.Header().Get("Location"))
|
assert.Equal(t, "/api/path2/", w.Header().Get("Location"))
|
||||||
assert.Equal(t, 301, w.Code)
|
assert.Equal(t, 301, w.Code)
|
||||||
|
|
||||||
w = performRequest(router, "GET", "/path2/", header{Key: "X-Forwarded-Prefix", Value: "/api/"})
|
w = performRequest(router, http.MethodGet, "/path2/", header{Key: "X-Forwarded-Prefix", Value: "/api/"})
|
||||||
assert.Equal(t, 200, w.Code)
|
assert.Equal(t, 200, w.Code)
|
||||||
|
|
||||||
router.RedirectTrailingSlash = false
|
router.RedirectTrailingSlash = false
|
||||||
|
|
||||||
w = performRequest(router, "GET", "/path/")
|
w = performRequest(router, http.MethodGet, "/path/")
|
||||||
assert.Equal(t, http.StatusNotFound, w.Code)
|
assert.Equal(t, http.StatusNotFound, w.Code)
|
||||||
w = performRequest(router, "GET", "/path2")
|
w = performRequest(router, http.MethodGet, "/path2")
|
||||||
assert.Equal(t, http.StatusNotFound, w.Code)
|
assert.Equal(t, http.StatusNotFound, w.Code)
|
||||||
w = performRequest(router, "POST", "/path3/")
|
w = performRequest(router, http.MethodPost, "/path3/")
|
||||||
assert.Equal(t, http.StatusNotFound, w.Code)
|
assert.Equal(t, http.StatusNotFound, w.Code)
|
||||||
w = performRequest(router, "PUT", "/path4")
|
w = performRequest(router, http.MethodPut, "/path4")
|
||||||
assert.Equal(t, http.StatusNotFound, w.Code)
|
assert.Equal(t, http.StatusNotFound, w.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,19 +207,19 @@ func TestRouteRedirectFixedPath(t *testing.T) {
|
|||||||
router.POST("/PATH3", func(c *Context) {})
|
router.POST("/PATH3", func(c *Context) {})
|
||||||
router.POST("/Path4/", func(c *Context) {})
|
router.POST("/Path4/", func(c *Context) {})
|
||||||
|
|
||||||
w := performRequest(router, "GET", "/PATH")
|
w := performRequest(router, http.MethodGet, "/PATH")
|
||||||
assert.Equal(t, "/path", w.Header().Get("Location"))
|
assert.Equal(t, "/path", w.Header().Get("Location"))
|
||||||
assert.Equal(t, http.StatusMovedPermanently, w.Code)
|
assert.Equal(t, http.StatusMovedPermanently, w.Code)
|
||||||
|
|
||||||
w = performRequest(router, "GET", "/path2")
|
w = performRequest(router, http.MethodGet, "/path2")
|
||||||
assert.Equal(t, "/Path2", w.Header().Get("Location"))
|
assert.Equal(t, "/Path2", w.Header().Get("Location"))
|
||||||
assert.Equal(t, http.StatusMovedPermanently, w.Code)
|
assert.Equal(t, http.StatusMovedPermanently, w.Code)
|
||||||
|
|
||||||
w = performRequest(router, "POST", "/path3")
|
w = performRequest(router, http.MethodPost, "/path3")
|
||||||
assert.Equal(t, "/PATH3", w.Header().Get("Location"))
|
assert.Equal(t, "/PATH3", w.Header().Get("Location"))
|
||||||
assert.Equal(t, http.StatusTemporaryRedirect, w.Code)
|
assert.Equal(t, http.StatusTemporaryRedirect, w.Code)
|
||||||
|
|
||||||
w = performRequest(router, "POST", "/path4")
|
w = performRequest(router, http.MethodPost, "/path4")
|
||||||
assert.Equal(t, "/Path4/", w.Header().Get("Location"))
|
assert.Equal(t, "/Path4/", w.Header().Get("Location"))
|
||||||
assert.Equal(t, http.StatusTemporaryRedirect, w.Code)
|
assert.Equal(t, http.StatusTemporaryRedirect, w.Code)
|
||||||
}
|
}
|
||||||
@ -249,7 +249,7 @@ func TestRouteParamsByName(t *testing.T) {
|
|||||||
assert.False(t, ok)
|
assert.False(t, ok)
|
||||||
})
|
})
|
||||||
|
|
||||||
w := performRequest(router, "GET", "/test/john/smith/is/super/great")
|
w := performRequest(router, http.MethodGet, "/test/john/smith/is/super/great")
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
assert.Equal(t, "john", name)
|
assert.Equal(t, "john", name)
|
||||||
@ -283,7 +283,7 @@ func TestRouteParamsByNameWithExtraSlash(t *testing.T) {
|
|||||||
assert.False(t, ok)
|
assert.False(t, ok)
|
||||||
})
|
})
|
||||||
|
|
||||||
w := performRequest(router, "GET", "//test//john//smith//is//super//great")
|
w := performRequest(router, http.MethodGet, "//test//john//smith//is//super//great")
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
assert.Equal(t, "john", name)
|
assert.Equal(t, "john", name)
|
||||||
@ -311,16 +311,16 @@ func TestRouteStaticFile(t *testing.T) {
|
|||||||
router.Static("/using_static", dir)
|
router.Static("/using_static", dir)
|
||||||
router.StaticFile("/result", f.Name())
|
router.StaticFile("/result", f.Name())
|
||||||
|
|
||||||
w := performRequest(router, "GET", "/using_static/"+filename)
|
w := performRequest(router, http.MethodGet, "/using_static/"+filename)
|
||||||
w2 := performRequest(router, "GET", "/result")
|
w2 := performRequest(router, http.MethodGet, "/result")
|
||||||
|
|
||||||
assert.Equal(t, w, w2)
|
assert.Equal(t, w, w2)
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
assert.Equal(t, "Gin Web Framework", w.Body.String())
|
assert.Equal(t, "Gin Web Framework", w.Body.String())
|
||||||
assert.Equal(t, "text/plain; charset=utf-8", w.Header().Get("Content-Type"))
|
assert.Equal(t, "text/plain; charset=utf-8", w.Header().Get("Content-Type"))
|
||||||
|
|
||||||
w3 := performRequest(router, "HEAD", "/using_static/"+filename)
|
w3 := performRequest(router, http.MethodHead, "/using_static/"+filename)
|
||||||
w4 := performRequest(router, "HEAD", "/result")
|
w4 := performRequest(router, http.MethodHead, "/result")
|
||||||
|
|
||||||
assert.Equal(t, w3, w4)
|
assert.Equal(t, w3, w4)
|
||||||
assert.Equal(t, http.StatusOK, w3.Code)
|
assert.Equal(t, http.StatusOK, w3.Code)
|
||||||
@ -331,7 +331,7 @@ func TestRouteStaticListingDir(t *testing.T) {
|
|||||||
router := New()
|
router := New()
|
||||||
router.StaticFS("/", Dir("./", true))
|
router.StaticFS("/", Dir("./", true))
|
||||||
|
|
||||||
w := performRequest(router, "GET", "/")
|
w := performRequest(router, http.MethodGet, "/")
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
assert.Contains(t, w.Body.String(), "gin.go")
|
assert.Contains(t, w.Body.String(), "gin.go")
|
||||||
@ -343,7 +343,7 @@ func TestRouteStaticNoListing(t *testing.T) {
|
|||||||
router := New()
|
router := New()
|
||||||
router.Static("/", "./")
|
router.Static("/", "./")
|
||||||
|
|
||||||
w := performRequest(router, "GET", "/")
|
w := performRequest(router, http.MethodGet, "/")
|
||||||
|
|
||||||
assert.Equal(t, http.StatusNotFound, w.Code)
|
assert.Equal(t, http.StatusNotFound, w.Code)
|
||||||
assert.NotContains(t, w.Body.String(), "gin.go")
|
assert.NotContains(t, w.Body.String(), "gin.go")
|
||||||
@ -358,7 +358,7 @@ func TestRouterMiddlewareAndStatic(t *testing.T) {
|
|||||||
})
|
})
|
||||||
static.Static("/", "./")
|
static.Static("/", "./")
|
||||||
|
|
||||||
w := performRequest(router, "GET", "/gin.go")
|
w := performRequest(router, http.MethodGet, "/gin.go")
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
assert.Contains(t, w.Body.String(), "package gin")
|
assert.Contains(t, w.Body.String(), "package gin")
|
||||||
@ -372,13 +372,13 @@ func TestRouteNotAllowedEnabled(t *testing.T) {
|
|||||||
router := New()
|
router := New()
|
||||||
router.HandleMethodNotAllowed = true
|
router.HandleMethodNotAllowed = true
|
||||||
router.POST("/path", func(c *Context) {})
|
router.POST("/path", func(c *Context) {})
|
||||||
w := performRequest(router, "GET", "/path")
|
w := performRequest(router, http.MethodGet, "/path")
|
||||||
assert.Equal(t, http.StatusMethodNotAllowed, w.Code)
|
assert.Equal(t, http.StatusMethodNotAllowed, w.Code)
|
||||||
|
|
||||||
router.NoMethod(func(c *Context) {
|
router.NoMethod(func(c *Context) {
|
||||||
c.String(http.StatusTeapot, "responseText")
|
c.String(http.StatusTeapot, "responseText")
|
||||||
})
|
})
|
||||||
w = performRequest(router, "GET", "/path")
|
w = performRequest(router, http.MethodGet, "/path")
|
||||||
assert.Equal(t, "responseText", w.Body.String())
|
assert.Equal(t, "responseText", w.Body.String())
|
||||||
assert.Equal(t, http.StatusTeapot, w.Code)
|
assert.Equal(t, http.StatusTeapot, w.Code)
|
||||||
}
|
}
|
||||||
@ -387,9 +387,9 @@ func TestRouteNotAllowedEnabled2(t *testing.T) {
|
|||||||
router := New()
|
router := New()
|
||||||
router.HandleMethodNotAllowed = true
|
router.HandleMethodNotAllowed = true
|
||||||
// add one methodTree to trees
|
// add one methodTree to trees
|
||||||
router.addRoute("POST", "/", HandlersChain{func(_ *Context) {}})
|
router.addRoute(http.MethodPost, "/", HandlersChain{func(_ *Context) {}})
|
||||||
router.GET("/path2", func(c *Context) {})
|
router.GET("/path2", func(c *Context) {})
|
||||||
w := performRequest(router, "POST", "/path2")
|
w := performRequest(router, http.MethodPost, "/path2")
|
||||||
assert.Equal(t, http.StatusMethodNotAllowed, w.Code)
|
assert.Equal(t, http.StatusMethodNotAllowed, w.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,13 +397,13 @@ func TestRouteNotAllowedDisabled(t *testing.T) {
|
|||||||
router := New()
|
router := New()
|
||||||
router.HandleMethodNotAllowed = false
|
router.HandleMethodNotAllowed = false
|
||||||
router.POST("/path", func(c *Context) {})
|
router.POST("/path", func(c *Context) {})
|
||||||
w := performRequest(router, "GET", "/path")
|
w := performRequest(router, http.MethodGet, "/path")
|
||||||
assert.Equal(t, http.StatusNotFound, w.Code)
|
assert.Equal(t, http.StatusNotFound, w.Code)
|
||||||
|
|
||||||
router.NoMethod(func(c *Context) {
|
router.NoMethod(func(c *Context) {
|
||||||
c.String(http.StatusTeapot, "responseText")
|
c.String(http.StatusTeapot, "responseText")
|
||||||
})
|
})
|
||||||
w = performRequest(router, "GET", "/path")
|
w = performRequest(router, http.MethodGet, "/path")
|
||||||
assert.Equal(t, "404 page not found", w.Body.String())
|
assert.Equal(t, "404 page not found", w.Body.String())
|
||||||
assert.Equal(t, http.StatusNotFound, w.Code)
|
assert.Equal(t, http.StatusNotFound, w.Code)
|
||||||
}
|
}
|
||||||
@ -453,7 +453,7 @@ func TestRouterNotFound(t *testing.T) {
|
|||||||
{"/nope", http.StatusNotFound, ""}, // NotFound
|
{"/nope", http.StatusNotFound, ""}, // NotFound
|
||||||
}
|
}
|
||||||
for _, tr := range testRoutes {
|
for _, tr := range testRoutes {
|
||||||
w := performRequest(router, "GET", tr.route)
|
w := performRequest(router, http.MethodGet, tr.route)
|
||||||
assert.Equal(t, tr.code, w.Code)
|
assert.Equal(t, tr.code, w.Code)
|
||||||
if w.Code != http.StatusNotFound {
|
if w.Code != http.StatusNotFound {
|
||||||
assert.Equal(t, tr.location, fmt.Sprint(w.Header().Get("Location")))
|
assert.Equal(t, tr.location, fmt.Sprint(w.Header().Get("Location")))
|
||||||
@ -466,20 +466,20 @@ func TestRouterNotFound(t *testing.T) {
|
|||||||
c.AbortWithStatus(http.StatusNotFound)
|
c.AbortWithStatus(http.StatusNotFound)
|
||||||
notFound = true
|
notFound = true
|
||||||
})
|
})
|
||||||
w := performRequest(router, "GET", "/nope")
|
w := performRequest(router, http.MethodGet, "/nope")
|
||||||
assert.Equal(t, http.StatusNotFound, w.Code)
|
assert.Equal(t, http.StatusNotFound, w.Code)
|
||||||
assert.True(t, notFound)
|
assert.True(t, notFound)
|
||||||
|
|
||||||
// Test other method than GET (want 307 instead of 301)
|
// Test other method than GET (want 307 instead of 301)
|
||||||
router.PATCH("/path", func(c *Context) {})
|
router.PATCH("/path", func(c *Context) {})
|
||||||
w = performRequest(router, "PATCH", "/path/")
|
w = performRequest(router, http.MethodPatch, "/path/")
|
||||||
assert.Equal(t, http.StatusTemporaryRedirect, w.Code)
|
assert.Equal(t, http.StatusTemporaryRedirect, w.Code)
|
||||||
assert.Equal(t, "map[Location:[/path]]", fmt.Sprint(w.Header()))
|
assert.Equal(t, "map[Location:[/path]]", fmt.Sprint(w.Header()))
|
||||||
|
|
||||||
// Test special case where no node for the prefix "/" exists
|
// Test special case where no node for the prefix "/" exists
|
||||||
router = New()
|
router = New()
|
||||||
router.GET("/a", func(c *Context) {})
|
router.GET("/a", func(c *Context) {})
|
||||||
w = performRequest(router, "GET", "/")
|
w = performRequest(router, http.MethodGet, "/")
|
||||||
assert.Equal(t, http.StatusNotFound, w.Code)
|
assert.Equal(t, http.StatusNotFound, w.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -490,10 +490,10 @@ func TestRouterStaticFSNotFound(t *testing.T) {
|
|||||||
c.String(404, "non existent")
|
c.String(404, "non existent")
|
||||||
})
|
})
|
||||||
|
|
||||||
w := performRequest(router, "GET", "/nonexistent")
|
w := performRequest(router, http.MethodGet, "/nonexistent")
|
||||||
assert.Equal(t, "non existent", w.Body.String())
|
assert.Equal(t, "non existent", w.Body.String())
|
||||||
|
|
||||||
w = performRequest(router, "HEAD", "/nonexistent")
|
w = performRequest(router, http.MethodHead, "/nonexistent")
|
||||||
assert.Equal(t, "non existent", w.Body.String())
|
assert.Equal(t, "non existent", w.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,7 +503,7 @@ func TestRouterStaticFSFileNotFound(t *testing.T) {
|
|||||||
router.StaticFS("/", http.FileSystem(http.Dir(".")))
|
router.StaticFS("/", http.FileSystem(http.Dir(".")))
|
||||||
|
|
||||||
assert.NotPanics(t, func() {
|
assert.NotPanics(t, func() {
|
||||||
performRequest(router, "GET", "/nonexistent")
|
performRequest(router, http.MethodGet, "/nonexistent")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -520,11 +520,11 @@ func TestMiddlewareCalledOnceByRouterStaticFSNotFound(t *testing.T) {
|
|||||||
router.StaticFS("/", http.FileSystem(http.Dir("/thisreallydoesntexist/")))
|
router.StaticFS("/", http.FileSystem(http.Dir("/thisreallydoesntexist/")))
|
||||||
|
|
||||||
// First access
|
// First access
|
||||||
performRequest(router, "GET", "/nonexistent")
|
performRequest(router, http.MethodGet, "/nonexistent")
|
||||||
assert.Equal(t, 1, middlewareCalledNum)
|
assert.Equal(t, 1, middlewareCalledNum)
|
||||||
|
|
||||||
// Second access
|
// Second access
|
||||||
performRequest(router, "HEAD", "/nonexistent")
|
performRequest(router, http.MethodHead, "/nonexistent")
|
||||||
assert.Equal(t, 2, middlewareCalledNum)
|
assert.Equal(t, 2, middlewareCalledNum)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -543,7 +543,7 @@ func TestRouteRawPath(t *testing.T) {
|
|||||||
assert.Equal(t, "222", num)
|
assert.Equal(t, "222", num)
|
||||||
})
|
})
|
||||||
|
|
||||||
w := performRequest(route, "POST", "/project/Some%2FOther%2FProject/build/222")
|
w := performRequest(route, http.MethodPost, "/project/Some%2FOther%2FProject/build/222")
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,7 +563,7 @@ func TestRouteRawPathNoUnescape(t *testing.T) {
|
|||||||
assert.Equal(t, "333", num)
|
assert.Equal(t, "333", num)
|
||||||
})
|
})
|
||||||
|
|
||||||
w := performRequest(route, "POST", "/project/Some%2FOther%2FProject/build/333")
|
w := performRequest(route, http.MethodPost, "/project/Some%2FOther%2FProject/build/333")
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -574,7 +574,7 @@ func TestRouteServeErrorWithWriteHeader(t *testing.T) {
|
|||||||
c.Next()
|
c.Next()
|
||||||
})
|
})
|
||||||
|
|
||||||
w := performRequest(route, "GET", "/NotFound")
|
w := performRequest(route, http.MethodGet, "/NotFound")
|
||||||
assert.Equal(t, 421, w.Code)
|
assert.Equal(t, 421, w.Code)
|
||||||
assert.Equal(t, 0, w.Body.Len())
|
assert.Equal(t, 0, w.Body.Len())
|
||||||
}
|
}
|
||||||
@ -605,7 +605,7 @@ func TestRouteContextHoldsFullPath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
w := performRequest(router, "GET", route)
|
w := performRequest(router, http.MethodGet, route)
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -615,6 +615,6 @@ func TestRouteContextHoldsFullPath(t *testing.T) {
|
|||||||
assert.Equal(t, "", c.FullPath())
|
assert.Equal(t, "", c.FullPath())
|
||||||
})
|
})
|
||||||
|
|
||||||
w := performRequest(router, "GET", "/not-found")
|
w := performRequest(router, http.MethodGet, "/not-found")
|
||||||
assert.Equal(t, http.StatusNotFound, w.Code)
|
assert.Equal(t, http.StatusNotFound, w.Code)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user