goview

package
v2.2.2 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	Root:         "views",
	Extension:    ".html",
	Master:       "templates/master",
	Partials:     []string{},
	Funcs:        make(template.FuncMap),
	DisableCache: false,
	Delims:       Delims{Left: "{{", Right: "}}"},
}

DefaultConfig default config

View Source
var HTMLContentType = []string{"text/html; charset=utf-8"}

HTMLContentType const templateEngineKey = "httpx_templateEngine"

Functions

func Render

func Render(w http.ResponseWriter, status int, name string, data interface{}) error

Render render view template with default instance

func Use

func Use(engine *ViewEngine)

Use setting default instance engine

Types

type Config

type Config struct {
	Root         string           //view root
	Extension    string           //template extension
	Master       string           //template master
	Partials     []string         //template partial, such as head, foot
	Funcs        template.FuncMap //template functions
	DisableCache bool             //disable cache, debug mode
	Delims       Delims           //delimeters
}

Config configuration options

type Delims

type Delims struct {
	Left  string
	Right string
}

Delims delims for template

type FileHandler

type FileHandler func(config Config, tplFile string) (content string, err error)

FileHandler file handler interface

func DefaultFileHandler

func DefaultFileHandler() FileHandler

DefaultFileHandler new default file handler

type M

type M map[string]interface{}

M map interface for data

type ViewEngine

type ViewEngine struct {
	// contains filtered or unexported fields
}

ViewEngine view template engine

func Default

func Default() *ViewEngine

Default new default template engine

func New

func New(config Config) *ViewEngine

New new template engine

func (*ViewEngine) Render

func (e *ViewEngine) Render(w http.ResponseWriter, statusCode int, name string, data interface{}) error

Render render template with http.ResponseWriter

func (*ViewEngine) RenderWriter

func (e *ViewEngine) RenderWriter(w io.Writer, name string, data interface{}) error

RenderWriter render template with io.Writer

func (*ViewEngine) SetFileHandler

func (e *ViewEngine) SetFileHandler(handle FileHandler)

SetFileHandler set file handler

Jump to

Keyboard shortcuts

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