feat(engine): Kept the same case as the original method

Signed-off-by: Flc゛ <four_leaf_clover@foxmail.com>
This commit is contained in:
Flc゛ 2024-03-14 14:40:49 +08:00
parent ee54f404e5
commit e76630c7de
2 changed files with 21 additions and 21 deletions

View File

@ -12,50 +12,50 @@ func Use(middleware ...HandlerFunc) OptionFunc {
} }
} }
// Get is a shortcut for RouterGroup.Handle("GET", path, handle) // GET is a shortcut for RouterGroup.Handle("GET", path, handle)
func Get(path string, handlers ...HandlerFunc) OptionFunc { func GET(path string, handlers ...HandlerFunc) OptionFunc {
return func(e *Engine) { return func(e *Engine) {
e.GET(path, handlers...) e.GET(path, handlers...)
} }
} }
// Post is a shortcut for RouterGroup.Handle("POST", path, handle) // POST is a shortcut for RouterGroup.Handle("POST", path, handle)
func Post(path string, handlers ...HandlerFunc) OptionFunc { func POST(path string, handlers ...HandlerFunc) OptionFunc {
return func(e *Engine) { return func(e *Engine) {
e.POST(path, handlers...) e.POST(path, handlers...)
} }
} }
// Put is a shortcut for RouterGroup.Handle("PUT", path, handle) // PUT is a shortcut for RouterGroup.Handle("PUT", path, handle)
func Put(path string, handlers ...HandlerFunc) OptionFunc { func PUT(path string, handlers ...HandlerFunc) OptionFunc {
return func(e *Engine) { return func(e *Engine) {
e.PUT(path, handlers...) e.PUT(path, handlers...)
} }
} }
// Delete is a shortcut for RouterGroup.Handle("DELETE", path, handle) // DELETE is a shortcut for RouterGroup.Handle("DELETE", path, handle)
func Delete(path string, handlers ...HandlerFunc) OptionFunc { func DELETE(path string, handlers ...HandlerFunc) OptionFunc {
return func(e *Engine) { return func(e *Engine) {
e.DELETE(path, handlers...) e.DELETE(path, handlers...)
} }
} }
// Patch is a shortcut for RouterGroup.Handle("PATCH", path, handle) // PATCH is a shortcut for RouterGroup.Handle("PATCH", path, handle)
func Patch(path string, handlers ...HandlerFunc) OptionFunc { func PATCH(path string, handlers ...HandlerFunc) OptionFunc {
return func(e *Engine) { return func(e *Engine) {
e.PATCH(path, handlers...) e.PATCH(path, handlers...)
} }
} }
// Head is a shortcut for RouterGroup.Handle("HEAD", path, handle) // HEAD is a shortcut for RouterGroup.Handle("HEAD", path, handle)
func Head(path string, handlers ...HandlerFunc) OptionFunc { func HEAD(path string, handlers ...HandlerFunc) OptionFunc {
return func(e *Engine) { return func(e *Engine) {
e.HEAD(path, handlers...) e.HEAD(path, handlers...)
} }
} }
// Options is a shortcut for RouterGroup.Handle("OPTIONS", path, handle) // OPTIONS is a shortcut for RouterGroup.Handle("OPTIONS", path, handle)
func Options(path string, handlers ...HandlerFunc) OptionFunc { func OPTIONS(path string, handlers ...HandlerFunc) OptionFunc {
return func(e *Engine) { return func(e *Engine) {
e.OPTIONS(path, handlers...) e.OPTIONS(path, handlers...)
} }

View File

@ -30,7 +30,7 @@ func TestOption_HttpMethod(t *testing.T) {
{ {
method: http.MethodGet, method: http.MethodGet,
path: "/get", path: "/get",
optionFunc: Get("/get", func(c *Context) { optionFunc: GET("/get", func(c *Context) {
assert.Equal(t, http.MethodGet, c.Request.Method) assert.Equal(t, http.MethodGet, c.Request.Method)
assert.Equal(t, "/get", c.Request.URL.Path) assert.Equal(t, "/get", c.Request.URL.Path)
}), }),
@ -38,7 +38,7 @@ func TestOption_HttpMethod(t *testing.T) {
{ {
method: http.MethodPut, method: http.MethodPut,
path: "/put", path: "/put",
optionFunc: Put("/put", func(c *Context) { optionFunc: PUT("/put", func(c *Context) {
assert.Equal(t, http.MethodPut, c.Request.Method) assert.Equal(t, http.MethodPut, c.Request.Method)
assert.Equal(t, "/put", c.Request.URL.Path) assert.Equal(t, "/put", c.Request.URL.Path)
}), }),
@ -46,7 +46,7 @@ func TestOption_HttpMethod(t *testing.T) {
{ {
method: http.MethodPost, method: http.MethodPost,
path: "/post", path: "/post",
optionFunc: Post("/post", func(c *Context) { optionFunc: POST("/post", func(c *Context) {
assert.Equal(t, http.MethodPost, c.Request.Method) assert.Equal(t, http.MethodPost, c.Request.Method)
assert.Equal(t, "/post", c.Request.URL.Path) assert.Equal(t, "/post", c.Request.URL.Path)
}), }),
@ -54,7 +54,7 @@ func TestOption_HttpMethod(t *testing.T) {
{ {
method: http.MethodDelete, method: http.MethodDelete,
path: "/delete", path: "/delete",
optionFunc: Delete("/delete", func(c *Context) { optionFunc: DELETE("/delete", func(c *Context) {
assert.Equal(t, http.MethodDelete, c.Request.Method) assert.Equal(t, http.MethodDelete, c.Request.Method)
assert.Equal(t, "/delete", c.Request.URL.Path) assert.Equal(t, "/delete", c.Request.URL.Path)
}), }),
@ -62,7 +62,7 @@ func TestOption_HttpMethod(t *testing.T) {
{ {
method: http.MethodPatch, method: http.MethodPatch,
path: "/patch", path: "/patch",
optionFunc: Patch("/patch", func(c *Context) { optionFunc: PATCH("/patch", func(c *Context) {
assert.Equal(t, http.MethodPatch, c.Request.Method) assert.Equal(t, http.MethodPatch, c.Request.Method)
assert.Equal(t, "/patch", c.Request.URL.Path) assert.Equal(t, "/patch", c.Request.URL.Path)
}), }),
@ -70,7 +70,7 @@ func TestOption_HttpMethod(t *testing.T) {
{ {
method: http.MethodOptions, method: http.MethodOptions,
path: "/options", path: "/options",
optionFunc: Options("/options", func(c *Context) { optionFunc: OPTIONS("/options", func(c *Context) {
assert.Equal(t, http.MethodOptions, c.Request.Method) assert.Equal(t, http.MethodOptions, c.Request.Method)
assert.Equal(t, "/options", c.Request.URL.Path) assert.Equal(t, "/options", c.Request.URL.Path)
}), }),
@ -78,7 +78,7 @@ func TestOption_HttpMethod(t *testing.T) {
{ {
method: http.MethodHead, method: http.MethodHead,
path: "/head", path: "/head",
optionFunc: Head("/head", func(c *Context) { optionFunc: HEAD("/head", func(c *Context) {
assert.Equal(t, http.MethodHead, c.Request.Method) assert.Equal(t, http.MethodHead, c.Request.Method)
assert.Equal(t, "/head", c.Request.URL.Path) assert.Equal(t, "/head", c.Request.URL.Path)
}), }),