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)
}