Skip to content

Commit

Permalink
♻️ Refactor Ctx.Method func to improve code readability (#2647)
Browse files Browse the repository at this point in the history
* Refactor Ctx.Method func to improve code readability

* Fix the lint issue with extra tab on blank line
  • Loading branch information
dairlair authored Sep 26, 2023
1 parent 640fd1f commit c89184c
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,17 +927,24 @@ func (c *Ctx) Location(path string) {
c.setCanonical(HeaderLocation, path)
}

// Method contains a string corresponding to the HTTP method of the request: GET, POST, PUT and so on.
// Method returns the HTTP request method for the context, optionally overridden by the provided argument.
// If no override is given or if the provided override is not a valid HTTP method, it returns the current method from the context.
// Otherwise, it updates the context's method and returns the overridden method as a string.
func (c *Ctx) Method(override ...string) string {
if len(override) > 0 {
method := utils.ToUpper(override[0])
mINT := c.app.methodInt(method)
if mINT == -1 {
return c.method
}
c.method = method
c.methodINT = mINT
if len(override) == 0 {
// Nothing to override, just return current method from context
return c.method
}

method := utils.ToUpper(override[0])
mINT := c.app.methodInt(method)
if mINT == -1 {
// Provided override does not valid HTTP method, no override, return current method
return c.method
}

c.method = method
c.methodINT = mINT
return c.method
}

Expand Down

0 comments on commit c89184c

Please sign in to comment.