httpview

package module
v0.0.0-...-ef2706f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

httpview is a helper library to increase code reusability in other projects It is useful for streamlining rendering HTML and text templates. Inspired by https://www.calhoun.io/intro-to-templates-p4-v-in-mvc/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(r *http.Request, w io.Writer, name string, title string, data any) error

Executes chosen named template and writes it to provided io.Writer. This is the default way of executing templates in this library.

func NewViewData

func NewViewData(f func(*http.Request, string, any) (any, error))

Sets a user-defined function that returns standard struct passed to every template. It should accept HTTP request, HTML title and data for additional template values.

func SetLayoutDir

func SetLayoutDir(dir string)

Sets layout directory where the template base files are stored. All of this template files are included in each template.

Types

type Tmpl

type Tmpl map[string]*View

Type for holding template configurations (Views)

var Templates Tmpl

Global variable for holding template configurations (Views)

type View

type View struct {
	HTemplate *ht.Template
	TTemplate *tt.Template
	Layout    string
}

View holds template configuration

func NewViewHtml

func NewViewHtml(layoutName string, files ...string) (*View, error)

Creates new View named layoutName as HTML Template

func NewViewText

func NewViewText(layoutName string, files ...string) (*View, error)

Creates new View named layoutName as Text Template

func (*View) RenderHtml

func (v *View) RenderHtml(w io.Writer, data any) error

Renders HTML Template from View to io.Writer using custom data struct

func (*View) RenderText

func (v *View) RenderText(w io.Writer, data any) error

Renders Text Template from View to io.Writer using custom data struct

func (*View) SetViewHtml

func (v *View) SetViewHtml(files ...string) error

Sets HTML Template to existing View

func (*View) SetViewText

func (v *View) SetViewText(files ...string) error

Sets Text Template to existing View

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL