Documentation ¶
Index ¶
- func FromContext[T templateIfaceTypes[TT, FM], TT templateTypes, FM ~map[string]any](ctx context.Context) *render[T, TT, FM]
- func HTTPHandler[T templateIfaceTypes[TT, FM], TT templateTypes, FM ~map[string]any](render *render[T, TT, FM], f HTTPResponseHandler) http.HandlerFunc
- func New[T templateIfaceTypes[TT, FM], TT templateTypes, FM ~map[string]any](path, postfix string, enabledCache bool) *render[T, TT, FM]
- func NewFS[T templateIfaceTypes[TT, FM], TT templateTypes, FM ~map[string]any](fs fs.FS, path, postfix string, enabledCache bool) *render[T, TT, FM]
- func WithContext[T templateIfaceTypes[TT, FM], TT templateTypes, FM ~map[string]any](ctx context.Context, render *render[T, TT, FM]) context.Context
- type HTMLRender
- type HTTPResponse
- type HTTPResponseHandler
- type Params
- type PlainRender
- type ResponseHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromContext ¶ added in v2.2.0
func FromContext[T templateIfaceTypes[TT, FM], TT templateTypes, FM ~map[string]any](ctx context.Context) *render[T, TT, FM]
FromContext returns render from context
func HTTPHandler ¶
func HTTPHandler[T templateIfaceTypes[TT, FM], TT templateTypes, FM ~map[string]any](render *render[T, TT, FM], f HTTPResponseHandler) http.HandlerFunc
HTTPHandler reponse wrapper for default http handler
Example: mux := http.NewServeMux() mux.HandleFunc("/", HTTPHandler(render, func(w http.ResponseWriter, r *http.Request) *HTTPResponse){ return Response(http.StatusOK, "index", params) }) mux.HandleFunc("/hello", HTTPHandler(render, getHello))
func New ¶
func New[T templateIfaceTypes[TT, FM], TT templateTypes, FM ~map[string]any](path, postfix string, enabledCache bool) *render[T, TT, FM]
New creates new template render with some option params
@param path - to the directory of templates @param postfix - after file name. You can render template just with name "index", "search" and etc and set the extension of file in the postfix @param enabledCache - option
func NewFS ¶
func NewFS[T templateIfaceTypes[TT, FM], TT templateTypes, FM ~map[string]any](fs fs.FS, path, postfix string, enabledCache bool) *render[T, TT, FM]
NewFS creates new template render with some option params for FS object
@param fs - preinited directory in memory @param path - to the directory of templates inside FS @param postfix - after file name. You can render template just with name "index", "search" and etc and set the extension of file in the postfix @param enabledCache - option
Types ¶
type HTMLRender ¶ added in v2.2.0
type HTMLRender = render[*htmltemplate.Template, htmltemplate.Template, htmltemplate.FuncMap]
func FromContextHTML ¶ added in v2.2.0
func FromContextHTML(ctx context.Context) *HTMLRender
FromContextHTML returns render from context
func NewHTML ¶ added in v2.2.0
func NewHTML(path, postfix string, enabledCache bool) *HTMLRender
NewHTML creates new template render with some option params
@param path - to the directory of templates @param postfix - after file name. You can render template just with name "index", "search" and etc and set the extension of file in the postfix @param enabledCache - option
func NewHTMLFS ¶ added in v2.2.0
func NewHTMLFS(fs fs.FS, path, postfix string, enabledCache bool) *HTMLRender
NewHTMLFS creates new template render with some option params for FS object
@param fs - preinited directory in memory @param path - to the directory of templates inside FS @param postfix - after file name. You can render template just with name "index", "search" and etc and set the extension of file in the postfix @param enabledCache - option
type HTTPResponse ¶
type HTTPResponse struct { Request *http.Request Writer http.ResponseWriter Template string Context Params Error error Code int }
HTTPResponse represents HTTP response with all necessary information
func Response ¶
func Response(code int, template string, ctx Params) *HTTPResponse
Response returns new response object for HTTPHandler wrapper
func (*HTTPResponse) ExtendParams ¶
func (resp *HTTPResponse) ExtendParams(ctx Params) *HTTPResponse
ExtendParams which will be passed to the renderer
func (*HTTPResponse) SetParams ¶
func (resp *HTTPResponse) SetParams(ctx Params) *HTTPResponse
SetParams which will be passed to the renderer
type HTTPResponseHandler ¶
type HTTPResponseHandler func(w http.ResponseWriter, r *http.Request) *HTTPResponse
HTTPResponseHandler represents default HTTP response handlerer
type PlainRender ¶ added in v2.2.0
type PlainRender = render[*texttemplate.Template, texttemplate.Template, texttemplate.FuncMap]
func FromContextPlain ¶ added in v2.2.0
func FromContextPlain(ctx context.Context) *PlainRender
FromContextPlain returns render from context
func NewPlain ¶ added in v2.2.0
func NewPlain(path, postfix string, enabledCache bool) *PlainRender
NewPlain creates new template render with some option params
@param path - to the directory of templates @param postfix - after file name. You can render template just with name "index", "search" and etc and set the extension of file in the postfix @param enabledCache - option
func NewPlainFS ¶ added in v2.2.0
func NewPlainFS(fs fs.FS, path, postfix string, enabledCache bool) *PlainRender
NewPlainFS creates new template render with some option params for FS object
@param fs - preinited directory in memory @param path - to the directory of templates inside FS @param postfix - after file name. You can render template just with name "index", "search" and etc and set the extension of file in the postfix @param enabledCache - option
type ResponseHandler ¶
type ResponseHandler func(*HTTPResponse) error
ResponseHandler for the particular HTTP code