1
0
Fork 0
Yet another HTTP router. But this one allows any combinations of regular and param segments for a path.
Go to file
Alexander Andreev 32ae3a3d0d
A little optimisation in get() and add() methods.
2023-09-05 18:14:56 +04:00
.gitignore Init repo! 2023-05-26 04:06:35 +04:00
LICENSE A year and copyright holders weren't filled in a LICENSE, LOL. 2023-07-23 23:27:49 +04:00
README.md Also added sub-path to an example in the README.md. 2023-08-11 18:46:49 +04:00
go.mod Init repo! 2023-05-26 04:06:35 +04:00
httpr.go A little optimisation in get() and add() methods. 2023-09-05 18:14:56 +04:00
httpr_test.go Added a test for path parsing and benchmarks for newPath and newServePath. 2023-09-05 06:03:29 +04:00

README.md

httpr

It is an implementation of yet another HTTP router.

The reason why this router was made is to be able to have pretty paths with parameters and regular endpoints at the same level. Like this:

GET /:a/:b
GET /assets/*filepath

In routers like httprouter this is not allowed.

This router is used like many others., example:

r := httpr.New()

r.Handler(http.MethodGet, "/", func(w http.ResponseWriter, r *http.Request) {
	...
})

r.ServeStatic("/assets/*filepath", http.FS(os.Dir(".")))

r.NotFoundHandler = func(w http.ResponseWriter, r *http.Request) {
	...
}

s := r.Sub("/api/v1")

s.Handler(http.MethodGet, "/", func(w http.ResponseWriter, r *http.Request) {
	...
})

if err := http.ListenAndServe(":8000", r); err != nil {
	...
}