🔗 HTTP router based on radix trees. 12 Commits
2023-07-09 21:24:24 +02:00
2023-09-01 12:43:36 +02:00
2023-09-01 12:43:36 +02:00
2023-09-01 12:43:36 +02:00
2023-09-01 12:43:36 +02:00
2023-09-01 12:43:36 +02:00
2023-07-09 17:46:17 +02:00
2023-09-01 12:43:36 +02:00
2023-09-01 12:43:36 +02:00
2023-07-18 17:14:34 +02:00
2023-07-29 17:00:10 +02:00
2023-09-01 12:43:36 +02:00

router

HTTP router based on radix trees.

Features

  • Efficient lookup
  • Generic data structure
  • Zero dependencies (excluding tests)

Installation

go get git.akyoto.dev/go/router

Usage

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: TestWildcard
PASS: TestMethods
PASS: TestGitHub
coverage: 76.9% of statements

Benchmarks

BenchmarkLookup-12               6965749               171.2 ns/op            96 B/op          2 allocs/op
BenchmarkLookupNoAlloc-12       24243546                48.5 ns/op             0 B/op          0 allocs/op

License

Please see the license documentation.

© 2023 Eduard Urbach