From de480c25bb4c77a7b9aa476a3e3a8a9e898d43f6 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sat, 6 May 2017 21:47:38 +0100 Subject: [PATCH] implement #88 on back-end --- handlers/search.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/handlers/search.go b/handlers/search.go index 63a97d25..22f3ca82 100644 --- a/handlers/search.go +++ b/handlers/search.go @@ -24,6 +24,8 @@ func Search(w http.ResponseWriter, r *http.Request, c *config.Config, u *config. message []byte ) + caseInsensitive := (r.URL.Query().Get("insensitive") == "true") + // Starts an infinite loop until a valid command is captured. for { _, message, err = conn.ReadMessage() @@ -37,6 +39,10 @@ func Search(w http.ResponseWriter, r *http.Request, c *config.Config, u *config. } } + if caseInsensitive { + search = strings.ToLower(search) + } + scope := strings.Replace(r.URL.Path, c.BaseURL, "", 1) scope = strings.TrimPrefix(scope, "/") scope = "/" + scope @@ -45,6 +51,10 @@ func Search(w http.ResponseWriter, r *http.Request, c *config.Config, u *config. scope = filepath.Clean(scope) err = filepath.Walk(scope, func(path string, f os.FileInfo, err error) error { + if caseInsensitive { + path = strings.ToLower(path) + } + if strings.Contains(path, search) { if !u.Allowed(path) { return nil