root.go 637 B

123456789101112131415161718192021222324252627282930313233
  1. package ss
  2. // The type implements the entry point
  3. // for all the request for the server.
  4. type RootRouter struct {
  5. handler Handler
  6. }
  7. // Return the new RootRouter with the specified
  8. // handler.
  9. func Root(handler Handler) *RootRouter {
  10. if handler == nil {
  11. panic("the root handler is nil")
  12. }
  13. ret := &RootRouter{}
  14. ret.handler = handler
  15. return ret
  16. }
  17. // Implementing the http.Handler .
  18. func (router *RootRouter) ServeHTTP(w ResponseWriter, r *Request) {
  19. ctx := Context{}
  20. ctx.W = w
  21. ctx.R = r
  22. u := *r.URL
  23. ctx.RelUrl = &u
  24. router.handler.Handle(&ctx)
  25. }
  26. func (router *RootRouter) Handle(c *Context) {
  27. router.handler.Handle(c)
  28. }