Documentation ¶
Overview ¶
Package hg provides utilities functions around opinionated patterns around "html for go".
Index ¶
- Variables
- func Handler[Model any](renderer ViewFunc[Model], options ...RenderOption[Model]) http.HandlerFunc
- func LongPollHandler(timeout time.Duration) http.HandlerFunc
- type MsgHandler
- type Redirect
- type RenderOption
- func Case[Model, Evt any](alias string, update UpdateFunc[Model, Evt]) RenderOption[Model]
- func CaseWithQualifier[Model, Msg any](update UpdateFunc[Model, Msg]) RenderOption[Model]
- func OnRequest[Model any](f UpdReqFunc[Model]) RenderOption[Model]
- func Update[Model any](messages ...MsgHandler[Model]) RenderOption[Model]
- type RequestUpdateFunc
- type TplFile
- type TplFilePreprocessor
- type TplOption
- type TplPreprocessor
- type UpdReqFunc
- type UpdateFunc
- type ViewFunc
- type ViewHtmlFunc
Constants ¶
This section is empty.
Variables ¶
var Assets embed.FS
Assets contains a small js shim containing the request-response utilities and the idiomorph library.
var Tailwind embed.FS
Tailwind contains a bundled CDN version of tailwind, which uses a JIT compiler to support all tailwind features on the fly. Its usage is not really recommended for production sites, however it works good enough for small things. Also, you can always decide to not include it and instead use the tailwind cli to compile a tailored version.
Functions ¶
func Handler ¶
func Handler[Model any](renderer ViewFunc[Model], options ...RenderOption[Model]) http.HandlerFunc
Handler builds a http handlerfunc based on a model-view transformation
func LongPollHandler ¶
func LongPollHandler(timeout time.Duration) http.HandlerFunc
Types ¶
type MsgHandler ¶
type MsgHandler[Model any] interface { Alias() string Transform(in Model, r *http.Request) (Model, error) }
A MsgHandler transforms an incoming request into a new Model state.
type Redirect ¶
type Redirect struct {
// contains filtered or unexported fields
}
Redirect offers the possibility to send non-http redirection requests (JSON) to the javascript shim, which evaluates the redirection response and applies the according navigation stack operation. This kind of navigation is not possible by using standard http redirects.
func Forward ¶
Forward creates a new forward Redirect to the given url. Use query parameters to provide some (bookmarkable) contextual information.
func (Redirect) Redirection ¶
type RenderOption ¶
type RenderOption[Model any] func(hnd *rHnd[Model])
RenderOptions provides a package private Options pattern.
func Case ¶
func Case[Model, Evt any](alias string, update UpdateFunc[Model, Evt]) RenderOption[Model]
Case is invoked if the message alias is matched and tries to unmarshal the form value _eventData message into a new value of type Msg. It then calls the UpdateFunc to transform the given Model into a new state. To apply navigation, see also Redirect.
func CaseWithQualifier ¶
func CaseWithQualifier[Model, Msg any](update UpdateFunc[Model, Msg]) RenderOption[Model]
CaseWithQualifier is like Case but uses as alias the package path and the type Name of the Message.
func OnRequest ¶
func OnRequest[Model any](f UpdReqFunc[Model]) RenderOption[Model]
OnRequest sets the first untyped transformer which is called for each request to the handler. This always happens, independently if a message has been sent. Thus, this transformer is especially helpful to inject any transitional state, which cannot be serialized, even things like contexts or use case services.
There can be only one OnRequest update function. The last call replaces the prior registered func.
func Update ¶
func Update[Model any](messages ...MsgHandler[Model]) RenderOption[Model]
Update is the entry point to register a bunch of message handlers. See also Case and CaseWithQualifier for shortcuts. Any already registered handlers (see Alias) are replaced.
type RequestUpdateFunc ¶
RequestUpdateFunc mutates the model by decode and applying the msg and returning an altered Model.
type TplFile ¶
func (*TplFile) RenameTplStmts ¶
RenameTplStmts replaces all {{ template "<oldname>" .}} occurrences with {{ template "<newname>" .}}
type TplFilePreprocessor ¶
type TplFilePreprocessor func(file *TplFile)
type TplOption ¶
type TplOption func(p *htmlParser)
func Execute ¶
Execute will invoke the given template Name instead of evaluating the entire template set anonymously.
func TplPreProc ¶
func TplPreProc(f TplPreprocessor) TplOption
func TplPreProcEach ¶
func TplPreProcEach(f TplFilePreprocessor) TplOption
type TplPreprocessor ¶
type UpdReqFunc ¶
type UpdateFunc ¶
type UpdateFunc[Model, Evt any] func(model Model, evt Evt) Model
UpdateFunc mutates the model by applying the Msg and returning an altered Model.
type ViewFunc ¶
type ViewFunc[Model any] func(w http.ResponseWriter, r *http.Request, model Model)
func (ViewFunc[Model]) Handle ¶
func (f ViewFunc[Model]) Handle(model Model) http.HandlerFunc
type ViewHtmlFunc ¶
ViewHtmlFunc transforms a Model into a raw HTML string.
func (ViewHtmlFunc[Model]) Handle ¶
func (f ViewHtmlFunc[Model]) Handle(model Model) http.HandlerFunc