From b1d607a8991147c4f3c905cd4e766eb35c83fdfa Mon Sep 17 00:00:00 2001 From: Kirill Motkov Date: Tue, 21 May 2019 18:08:52 +0300 Subject: [PATCH] Some code improvements (#1909) * strings.ToLower comparison changed to strings.EqualFold. * Rewrite switch statement with only one case as if. --- binding/form_mapping.go | 4 +--- context.go | 2 +- tree.go | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/binding/form_mapping.go b/binding/form_mapping.go index 32c5b66..ebf3b19 100644 --- a/binding/form_mapping.go +++ b/binding/form_mapping.go @@ -126,9 +126,7 @@ func tryToSetValue(value reflect.Value, field reflect.StructField, setter setter for len(opts) > 0 { opt, opts = head(opts, ",") - k, v := head(opt, "=") - switch k { - case "default": + if k, v := head(opt, "="); k == "default" { setOpt.isDefaultExists = true setOpt.defaultValue = v } diff --git a/context.go b/context.go index af747a1..a3a7bc4 100644 --- a/context.go +++ b/context.go @@ -671,7 +671,7 @@ func (c *Context) ContentType() string { // handshake is being initiated by the client. func (c *Context) IsWebsocket() bool { if strings.Contains(strings.ToLower(c.requestHeader("Connection")), "upgrade") && - strings.ToLower(c.requestHeader("Upgrade")) == "websocket" { + strings.EqualFold(c.requestHeader("Upgrade"), "websocket") { return true } return false diff --git a/tree.go b/tree.go index ada62ce..07d6b4b 100644 --- a/tree.go +++ b/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 // 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):] ciPath = append(ciPath, n.path...) @@ -618,7 +618,7 @@ func (n *node) findCaseInsensitivePath(path string, fixTrailingSlash bool) (ciPa return ciPath, true } 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 { return append(ciPath, n.path...), true }