2024-01-10 20:11:02 +03:00
|
|
|
package bond
|
|
|
|
|
|
|
|
// The type implements the entry point
|
|
|
|
// for all the request for the server.
|
|
|
|
type RootRouter struct {
|
|
|
|
handler Handler
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the new RootRouter with the specified
|
|
|
|
// handler.
|
|
|
|
func Root(handler Handler) *RootRouter {
|
|
|
|
if handler == nil {
|
|
|
|
panic("the root handler is nil")
|
|
|
|
}
|
|
|
|
ret := &RootRouter{}
|
|
|
|
ret.handler = handler
|
|
|
|
return ret
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implementing the http.Handler .
|
|
|
|
func (router *RootRouter) ServeHTTP(w ResponseWriter, r *Request) {
|
|
|
|
ctx := Context{}
|
|
|
|
ctx.W = w
|
|
|
|
ctx.R = r
|
2024-01-10 21:19:23 +03:00
|
|
|
u := *r.URL
|
|
|
|
ctx.RelUrl = &u
|
2024-01-10 20:11:02 +03:00
|
|
|
router.handler.Handle(&ctx)
|
|
|
|
}
|
2024-02-29 23:19:07 +03:00
|
|
|
|
|
|
|
func (router *RootRouter) Handle(c *Context) {
|
|
|
|
router.handler.Handle(c)
|
|
|
|
}
|