add browse file; move function to utils pkg

This commit is contained in:
Henrique Dias
2015-09-15 21:40:46 +01:00
parent 7a5e184610
commit 2300aa3a63
4 changed files with 38 additions and 26 deletions

View File

@@ -2,6 +2,7 @@ package utils
import (
"errors"
"net/http"
"reflect"
"strings"
"unicode"
@@ -57,3 +58,22 @@ func SplitCapitalize(name string) string {
return name
}
func ParseComponents(r *http.Request) []string {
//The URL that the user queried.
path := r.URL.Path
path = strings.TrimSpace(path)
//Cut off the leading and trailing forward slashes, if they exist.
//This cuts off the leading forward slash.
if strings.HasPrefix(path, "/") {
path = path[1:]
}
//This cuts off the trailing forward slash.
if strings.HasSuffix(path, "/") {
cutOffLastCharLen := len(path) - 1
path = path[:cutOffLastCharLen]
}
//We need to isolate the individual components of the path.
components := strings.Split(path, "/")
return components
}