2016-03-06 20:37:49 +00:00
|
|
|
package server
|
2016-03-06 19:18:46 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2016-03-06 20:37:49 +00:00
|
|
|
// ParseURLComponents parses the components of an URL creating an array
|
|
|
|
func ParseURLComponents(r *http.Request) []string {
|
2016-03-06 19:18:46 +00:00
|
|
|
//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
|
|
|
|
}
|