28 lines
532 B
Go
28 lines
532 B
Go
|
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
|
||
|
router.handler.Handle(&ctx)
|
||
|
}
|