// Create a new Cookoo HTTP handler. // // This will create an HTTP hanlder, but will not automatically attach it to a server. Implementors // can take the handler and attach it to an existing HTTP server wiht http.HandleFunc() or // http.ListenAndServe(). // // For simple web servers, using this package's Serve() function may be the easier route. // // Important details: // // - A URIPathResolver is used for resolving request names. // - The following datasources are added to the Context: // * url: A URLDatasource (Provides access to parts of the URL) // * path: A PathDatasource (Provides access to parts of a path. E.g. "/foo/bar") // * query: A QueryParameterDatasource (Provides access to URL query parameters.) // * post: A FormValuesDatasource (Provides access to form data or the body of a request.) // - The following context variables are set: // * http.Request: A pointer to the http.Request object // * http.ResponseWriter: The response writer. // * server.Address: The server's address and port (NOT ALWAYS PRESENT) func NewCookooHandler(reg *cookoo.Registry, router *cookoo.Router, cxt cookoo.Context) *CookooHandler { handler := new(CookooHandler) handler.Registry = reg handler.Router = router handler.BaseContext = cxt // Use the URI oriented request resolver in this package. resolver := new(URIPathResolver) resolver.Init(reg) router.SetRequestResolver(resolver) return handler }