view

package
v0.0.0-...-9816518 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2019 License: MIT Imports: 13 Imported by: 29

Documentation

Index

Constants

View Source
const (
	ContentTypeJSON   = "application/json"
	ContentTypeHTML   = "text/html"
	ContentTypePlain  = "text/plain"
	ContentTypeBinary = "application/octet-stream"

	CharSetUTF8 = "utf-8"
)

Variables

This section is empty.

Functions

func CloseWatcher

func CloseWatcher() error

CloseWatcher closes the wathcer.

func Html

func Html(name, contentType, charSet string) template

Html retruns a TemplateView witch uses HTML templates internally.

func InitHtmlTemplates

func InitHtmlTemplates(pattern string) (err error)

InitHtmlTemplates initialzes a series of HTML templates in the directory `pattern`.

func InitTextTemplates

func InitTextTemplates(pattern string) (err error)

InitTextTemplates initialzes a series of plain text templates in the directory `pattern`.

func InitWatcher

func InitWatcher(pattern string, f func(string) error, ef func(error)) (err error)

InitWatcher initialzes a watcher to watch templates changes in the `pattern`. f would be InitHtmlTemplates or InitTextTemplates. If the watcher raises an error internally, the callback function ef will be executed. ef can be nil witch represents ignoring all internal errors.

func Json

func Json(charSet string) json

func PreloadFile

func PreloadFile(filename string, contentType string) (preloadFile, error)

PreloadFile returns the view which can preload static files and serve them. The different between `StaticFile` and `PreloadFile` is that `StaticFile` load the content of file at every request, while `PreloadFile` load the content into memory at the initial stage. Despite that `PreloadFile` will be using more memories and could not update the content in time until restart the application, it should be fast than `StaticFile` in runtime.

func Simple

func Simple(contentType, charSet string) simple

func StaticFile

func StaticFile(filename string, contentType string) staticFile

StaticFile returns the view which can serve static files.

func Text

func Text(name, contentType, charSet string) template

Text retruns a TemplateView witch uses text templates internally.

Types

type View

type View interface {
	Render(interface{}) ([]byte, http.Header, error)
}

View is an interface to render response with a specific format.

Jump to

Keyboard shortcuts

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