Added router benchmarks

This commit is contained in:
Eduard Urbach 2024-03-12 20:35:19 +01:00
parent ea969d3aa2
commit b1e678bce7
Signed by: eduard
GPG key ID: 49226B848C78F6C8
10 changed files with 129 additions and 11 deletions

46
Route_test.go Normal file
View file

@ -0,0 +1,46 @@
package server_test
import (
"bufio"
"os"
"strings"
)
// Route represents a single line in the test data.
type Route struct {
Method string
Path string
}
// loadRoutes loads all routes from a text file.
func loadRoutes(filePath string) []Route {
var routes []Route
f, err := os.Open(filePath)
if err != nil {
panic(err)
}
defer f.Close()
reader := bufio.NewReader(f)
for {
line, err := reader.ReadString('\n')
if line != "" {
line = strings.TrimSpace(line)
parts := strings.Split(line, " ")
routes = append(routes, Route{
Method: parts[0],
Path: parts[1],
})
}
if err != nil {
break
}
}
return routes
}