This commit is contained in:
parent
336f317502
commit
06967e1593
2 changed files with 0 additions and 0 deletions
76
readme.md
Normal file
76
readme.md
Normal file
|
@ -0,0 +1,76 @@
|
|||
# router
|
||||
|
||||
HTTP router based on radix trees.
|
||||
|
||||
## Features
|
||||
|
||||
- Efficient lookup
|
||||
- Generic data structure
|
||||
- Zero dependencies (excluding tests)
|
||||
|
||||
## Installation
|
||||
|
||||
```shell
|
||||
go get git.urbach.dev/go/router
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```go
|
||||
router := router.New[string]()
|
||||
|
||||
// Static routes
|
||||
router.Add("GET", "/hello", "...")
|
||||
router.Add("GET", "/world", "...")
|
||||
|
||||
// Parameter routes
|
||||
router.Add("GET", "/users/:id", "...")
|
||||
router.Add("GET", "/users/:id/comments", "...")
|
||||
|
||||
// Wildcard routes
|
||||
router.Add("GET", "/images/*path", "...")
|
||||
|
||||
// Simple lookup
|
||||
data, params := router.Lookup("GET", "/users/42")
|
||||
fmt.Println(data, params)
|
||||
|
||||
// Efficient lookup
|
||||
data := router.LookupNoAlloc("GET", "/users/42", func(key string, value string) {
|
||||
fmt.Println(key, value)
|
||||
})
|
||||
```
|
||||
|
||||
## Tests
|
||||
|
||||
```
|
||||
PASS: TestStatic
|
||||
PASS: TestParameter
|
||||
PASS: TestMixed
|
||||
PASS: TestWildcard
|
||||
PASS: TestMap
|
||||
PASS: TestMethods
|
||||
PASS: TestGitHub
|
||||
PASS: TestTrailingSlash
|
||||
PASS: TestTrailingSlashOverwrite
|
||||
PASS: TestOverwrite
|
||||
PASS: TestInvalidMethod
|
||||
coverage: 100.0% of statements
|
||||
```
|
||||
|
||||
## Benchmarks
|
||||
|
||||
```
|
||||
BenchmarkBlog/Len1-Param0-12 211814850 5.646 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkBlog/Len1-Param1-12 132838722 8.978 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkGitHub/Len7-Param0-12 84768382 14.14 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkGitHub/Len7-Param1-12 55290044 20.74 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkGitHub/Len7-Param2-12 26057244 46.08 ns/op 0 B/op 0 allocs/op
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Please see the [license documentation](https://urbach.dev/license).
|
||||
|
||||
## Copyright
|
||||
|
||||
© 2023 Eduard Urbach
|
Loading…
Add table
Add a link
Reference in a new issue