Documentation ¶
Index ¶
- func Add(a, b int) int
- func CreateTemplateCache() (map[string]*template.Template, error)
- func DefaultData(td *models.TemplateData, r *http.Request) *models.TemplateData
- func FormatDate(t time.Time, f string) string
- func HumanDate(t time.Time) string
- func Iterate(count int) []int
- func NewRenderer(a *config.AppConfig)
- func Template(w http.ResponseWriter, r *http.Request, tmpl string, td *models.TemplateData) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateTemplateCache ¶
CreateTemplateCache creates a map of pre-parsed templates by parsing all the page templates and their corresponding layout templates. It returns a map of template names to their corresponding *template.Template pointers. It also returns an error if any error occurs while parsing the templates.
func DefaultData ¶
func DefaultData(td *models.TemplateData, r *http.Request) *models.TemplateData
DefaultData populates the default data for templates. It takes a pointer to a TemplateData struct and a pointer to an http.Request struct. It returns a pointer to a TemplateData struct.
func FormatDate ¶
FormatDate formats a given time.Time object to a string using the provided format string. The format string should be in the same format as the standard library's time package.
func HumanDate ¶
HumanDate takes a time.Time object and returns a string representation of the date in the format "2006-01-02".
func NewRenderer ¶
NewRenderer creates a new renderer with the given AppConfig.
func Template ¶
func Template(w http.ResponseWriter, r *http.Request, tmpl string, td *models.TemplateData) error
Template executes a given template with the provided TemplateData and writes the output to the http.ResponseWriter. If app.UseCache is true, it uses the template cache from app.TemplateCache, otherwise it creates a new cache using CreateTemplateCache(). It returns an error if the template cannot be found in the cache or if there is an error writing the template to the response writer.
Types ¶
This section is empty.