ss/root.go

34 lines
638 B
Go
Raw Permalink Normal View History

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
u := *r.URL
ctx.RelUrl = &u
router.handler.Handle(&ctx)
}
func (router *RootRouter) Handle(c *Context) {
router.handler.Handle(c)
}