package router_test import ( "bufio" "os" "strings" ) // route represents a single line in the router test file. type route struct { method string path string } // loadRoutes loads all routes from a text file. func loadRoutes(fileName string) []route { var routes []route for line := range linesInFile(fileName) { line = strings.TrimSpace(line) parts := strings.Split(line, " ") routes = append(routes, route{ method: parts[0], path: parts[1], }) } return routes } // linesInFile is a utility function to easily read every line in a text file. func linesInFile(fileName string) <-chan string { lines := make(chan string) go func() { defer close(lines) file, err := os.Open(fileName) if err != nil { return } defer file.Close() scanner := bufio.NewScanner(file) for scanner.Scan() { lines <- scanner.Text() } }() return lines } // noop serves as an empty addParameter function. func noop(string, string) {}