Package: rtr
Declarative routing utilities for Go web apps.
Repository: https://github.com/dracory/rtr
Install
go get github.com/dracory/rtr@latest
Quick Start
import (
"github.com/dracory/rtr"
"net/http"
)
func routes() []rtr.RouteInterface {
home := rtr.NewRoute().
SetName("Home").
SetPath("/").
SetHTMLHandler(func(w http.ResponseWriter, r *http.Request) string {
return "Hello"
})
return []rtr.RouteInterface{home}
}
Features
- Fluent builder:
SetName
,SetPath
,SetHTMLHandler
, etc. - Groups and middleware composition
- Simple integration with existing http servers
Example with multiple routes
func routes(app any) []rtr.RouteInterface {
about := rtr.NewRoute().
SetName("About").
SetPath("/about").
SetHTMLHandler(aboutController(app).Handler)
contact := rtr.NewRoute().
SetName("Contact").
SetPath("/contact").
SetHTMLHandler(contactController(app).Handler)
return []rtr.RouteInterface{about, contact}
}