{"modulePath":"github.com/raviraa/sql-ui","version":"v0.0.4","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package controller\n\n## Types\n\n```go\ntype Controller struct {\n\t// Container stores a services container which contains dependencies\n\tContainer *services.Container\n}\n```\nController provides base functionality and dependencies to routes. The proposed pattern is to embed a Controller in each individual route struct and to use the router to inject the container so your routes have access to the services within the container\n\n```go\nfunc NewController(c *services.Container) Controller\n```\nNewController creates a new Controller\n\n```go\nfunc (c *Controller) RenderPage(ctx *gin.Context, page Page)\n```\nRenderPage renders a Page as an HTTP response\n\n```go\ntype Page struct {\n\n\t// Title stores the title of the page\n\tTitle string\n\n\t// Context stores the request context\n\tContext *gin.Context\n\n\t// Path stores the path of the current request\n\tPath string\n\n\t// URL stores the URL of the current request\n\tURL string\n\n\t// Data stores whatever additional data that needs to be passed to the templates.\n\t// This is what the controller uses to pass the content of the page.\n\tData interface{}\n\n\t// Layout stores the name of the layout base template file which will be used when the page is rendered.\n\t// This should match a template file located within the layouts directory inside the templates directory.\n\t// The template extension should not be included in this value.\n\tLayout string\n\n\t// Name stores the name of the page as well as the name of the template file which will be used to render\n\t// the content portion of the layout template.\n\t// This should match a template file located within the pages directory inside the templates directory.\n\t// The template extension should not be included in this value.\n\tName string\n\n\t// HtmxBase is is base layout used in case of htmx requests\n\tHtmxBase string\n\n\t// TemplateExtra stores extra template names in pages directory that are needed to execute the page\n\tTemplateExtra []string\n\n\t// StatusCode stores the HTTP status code that will be returned\n\tStatusCode int\n\n\t// Headers stores a list of HTTP headers and values to be set on the response\n\tHeaders map[string]string\n\n\tHTMX struct {\n\t\tRequest  htmx.Request\n\t\tResponse *htmx.Response\n\t}\n\n\tContainer *services.Container\n}\n```\nPage consists of all data that will be used to render a page response for a given controller. While it's not required for a controller to render a Page on a route, this is the common data object that will be passed to the templates, making it easy for all controllers to share functionality both on the back and frontend. The Page can be expanded to include anything else your app wants to support. Methods on this page also then become available in the templates, which can be more useful than the funcmap if your methods require data stored in the page, such as the context.\n\n```go\nfunc NewPage(ctx *gin.Context, container *services.Container) Page\n```\nNewPage creates and initiatizes a new Page for a given request context\n\n","path":"github.com/raviraa/sql-ui/controller","name":"controller","synopsis":"","isRedistributable":true}
