Skip to content
Myr

Some code improvements (#1909)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* strings.ToLower comparison changed to strings.EqualFold. * Rewrite switch statement with only one case as if.

authored by Kirill Motkov · committed by 田欧 · parent 8ee9d95 · Browse files · 3 files+4 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+4 added−6 removed

  • other:+4 added−6 removed

3 files+4 added−6 removed

modified:binding/form_mapping.go+1 added-3 removed
124 unmodified lines
125 var opt string126 for len(opts) > 0 {127 opt, opts = head(opts, ",")128129 k, v := head(opt, "=")130 switch k {131 case "default":129 if k, v := head(opt, "="); k == "default" {130 setOpt.isDefaultExists = true131 setOpt.defaultValue = v132 }133 }
198 unmodified lines
modified:context.go+1 added-1 removed
669 unmodified lines
670// IsWebsocket returns true if the request headers indicate that a websocket671// handshake is being initiated by the client.672func (c *Context) IsWebsocket() bool {673 if strings.Contains(strings.ToLower(c.requestHeader("Connection")), "upgrade") &&674 strings.ToLower(c.requestHeader("Upgrade")) == "websocket" {674 strings.EqualFold(c.requestHeader("Upgrade"), "websocket") {675 return true676 }677 return false678}
345 unmodified lines
modified:tree.go+2 added-2 removed
512 unmodified lines
513func (n *node) findCaseInsensitivePath(path string, fixTrailingSlash bool) (ciPath []byte, found bool) {514 ciPath = make([]byte, 0, len(path)+1) // preallocate enough memory515516 // Outer loop for walking the tree517 for len(path) >= len(n.path) && strings.ToLower(path[:len(n.path)]) == strings.ToLower(n.path) {517 for len(path) >= len(n.path) && strings.EqualFold(path[:len(n.path)], n.path) {518 path = path[len(n.path):]519 ciPath = append(ciPath, n.path...)520521 if len(path) > 0 {
95 unmodified lines
617 if path == "/" {618 return ciPath, true619 }620 if len(path)+1 == len(n.path) && n.path[len(path)] == '/' &&621 strings.ToLower(path) == strings.ToLower(n.path[:len(path)]) &&621 strings.EqualFold(path, n.path[:len(path)]) &&622 n.handlers != nil {623 return append(ciPath, n.path...), true624 }625 }
2 unmodified lines