func TestSplitPathWithEmptyString(t *testing.T) { abs, params := helpers.SplitPath("") if abs != "" { t.Error("") } if params != "" { t.Error("") } }
func TestSplitPath(t *testing.T) { abs, params := helpers.SplitPath("/a/b/c?a=b&c=d") if abs != "/a/b/c" { t.Error("") } if params != "a=b&c=d" { t.Error("") } }
/** * Finding correct handler to certain method:path */ func Router(w http.ResponseWriter, req *http.Request) { // splitting whole path into parts path, paramsString := helpers.SplitPath(req.URL.String()) routeFound := false method := req.Method if IsWebsocket() { method = "WS" } // finding correct handler for rawPattern, _ := range routes[method] { pattern := helpers.PreparePattern(rawPattern) if pattern.MatchString(path) { routeFound = true // homage to Sinatra's splat splat = pattern.FindAllStringSubmatch(path, 100)[0][1:] // filling params params = helpers.ParseParams(paramsString) // calling matched handler fmt.Fprintln(w, routes[method][rawPattern]()) // terminal debugging if AppSettings["verbose-output"] != nil && AppSettings["verbose-output"].(bool) == true { log.Printf("%s %s\n", method, req.URL.String()) } break } } if !routeFound { NotFound(w, req) } }
func TestSplitPathWithoutParams(t *testing.T) { _, params := helpers.SplitPath("/a/b/c?") if params != "" { t.Error("") } }