Some code improvements (#1909)
* strings.ToLower comparison changed to strings.EqualFold. * Rewrite switch statement with only one case as if.
This commit is contained in:
parent
8ee9d959a0
commit
b1d607a899
@ -126,9 +126,7 @@ func tryToSetValue(value reflect.Value, field reflect.StructField, setter setter
|
|||||||
for len(opts) > 0 {
|
for len(opts) > 0 {
|
||||||
opt, opts = head(opts, ",")
|
opt, opts = head(opts, ",")
|
||||||
|
|
||||||
k, v := head(opt, "=")
|
if k, v := head(opt, "="); k == "default" {
|
||||||
switch k {
|
|
||||||
case "default":
|
|
||||||
setOpt.isDefaultExists = true
|
setOpt.isDefaultExists = true
|
||||||
setOpt.defaultValue = v
|
setOpt.defaultValue = v
|
||||||
}
|
}
|
||||||
|
@ -671,7 +671,7 @@ func (c *Context) ContentType() string {
|
|||||||
// handshake is being initiated by the client.
|
// handshake is being initiated by the client.
|
||||||
func (c *Context) IsWebsocket() bool {
|
func (c *Context) IsWebsocket() bool {
|
||||||
if strings.Contains(strings.ToLower(c.requestHeader("Connection")), "upgrade") &&
|
if strings.Contains(strings.ToLower(c.requestHeader("Connection")), "upgrade") &&
|
||||||
strings.ToLower(c.requestHeader("Upgrade")) == "websocket" {
|
strings.EqualFold(c.requestHeader("Upgrade"), "websocket") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
4
tree.go
4
tree.go
@ -514,7 +514,7 @@ func (n *node) findCaseInsensitivePath(path string, fixTrailingSlash bool) (ciPa
|
|||||||
ciPath = make([]byte, 0, len(path)+1) // preallocate enough memory
|
ciPath = make([]byte, 0, len(path)+1) // preallocate enough memory
|
||||||
|
|
||||||
// Outer loop for walking the tree
|
// Outer loop for walking the tree
|
||||||
for len(path) >= len(n.path) && strings.ToLower(path[:len(n.path)]) == strings.ToLower(n.path) {
|
for len(path) >= len(n.path) && strings.EqualFold(path[:len(n.path)], n.path) {
|
||||||
path = path[len(n.path):]
|
path = path[len(n.path):]
|
||||||
ciPath = append(ciPath, n.path...)
|
ciPath = append(ciPath, n.path...)
|
||||||
|
|
||||||
@ -618,7 +618,7 @@ func (n *node) findCaseInsensitivePath(path string, fixTrailingSlash bool) (ciPa
|
|||||||
return ciPath, true
|
return ciPath, true
|
||||||
}
|
}
|
||||||
if len(path)+1 == len(n.path) && n.path[len(path)] == '/' &&
|
if len(path)+1 == len(n.path) && n.path[len(path)] == '/' &&
|
||||||
strings.ToLower(path) == strings.ToLower(n.path[:len(path)]) &&
|
strings.EqualFold(path, n.path[:len(path)]) &&
|
||||||
n.handlers != nil {
|
n.handlers != nil {
|
||||||
return append(ciPath, n.path...), true
|
return append(ciPath, n.path...), true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user