Updated README.md.
This commit is contained in:
parent
fcbd09506a
commit
5d6a3630c6
34
README.md
34
README.md
@ -3,19 +3,27 @@
|
|||||||
It is an implementation of yet another HTTP router.
|
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
|
The reason why this router was made is to be able to have pretty paths with
|
||||||
parameters and standard endpoints at the same level.
|
parameters and regular endpoints at the same level. Like this:
|
||||||
|
|
||||||
As an example here is a structure used in my another project
|
GET /:a/:b
|
||||||
(dwelling-upload):
|
|
||||||
|
|
||||||
GET /
|
|
||||||
POST /
|
|
||||||
GET /:hash/:name
|
|
||||||
POST /delete
|
|
||||||
DELETE /:hash
|
|
||||||
GET /assets/*filepath
|
GET /assets/*filepath
|
||||||
GET /robots.txt
|
|
||||||
GET /favicon.svg
|
|
||||||
|
|
||||||
Previously I used httprouter and I had to have `/f/:hash/:name` route
|
In routers like httprouter this is not allowed.
|
||||||
instead of just `/:hash/:name` because of collisions.
|
|
||||||
|
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) {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := http.ListenAndServe(":8000", r); err != nil {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user