Documentation
¶
Index ¶
- Constants
- Variables
- func RenderVoidHTML(node *domu.Node, target io.Writer) error
- func RenderVoidHTMLDiff(node *domu.Node, target io.Writer) error
- func RenderVoidJSON(node *domu.Node, target io.Writer) error
- func RenderVoidJSONStream(node *domu.Node, target io.Writer) error
- type DOM
- type DOMFunc
- type DOMRegistry
- func (k *DOMRegistry) Add(km DOM, refName string)
- func (k *DOMRegistry) AddList(km []DOM, refName string)
- func (k *DOMRegistry) Clean(max time.Duration)
- func (k *DOMRegistry) Delete(refName string)
- func (k *DOMRegistry) DeleteList(refName string)
- func (k *DOMRegistry) Get(refName string) DOM
- func (k *DOMRegistry) GetList(refName string) []DOM
- func (k *DOMRegistry) Has(refName string) bool
- func (k *DOMRegistry) HasList(refName string) bool
- func (k *DOMRegistry) Reset()
- type DOMSet
- type Data
- type DefaultNotFound
- type Handler
- type HandlerFunc
- type Header
- type InsertOption
- type Layout
- type LayoutFunc
- type LiveDOM
- type LiveDOMList
- type Logger
- type Mux
- type MuxConfig
- type Node
- type NodeKeysSorter
- type OnPage
- type OnPages
- type Page
- func (pg *Page) AddLive(route string, targetName string) DOM
- func (pg *Page) AddStatic(name string, items ...DOM)
- func (pg *Page) Cleanup(maxDuration time.Duration)
- func (pg *Page) Close()
- func (pg *Page) GetRouting(name string) string
- func (pg *Page) HasLive(route string) bool
- func (pg *Page) HasStatic(name string) bool
- func (pg *Page) Live(route string) DOM
- func (pg *Page) OnPageAdd(fn OnPage)
- func (pg *Page) Render(d Data) *domu.Node
- func (pg *Page) Retire(name string)
- func (pg *Page) Serve(d Data) *domu.Node
- func (pg *Page) ServeLive(route string, handler Handler)
- func (pg *Page) ServeStatic(name string, handler Handler)
- func (pg *Page) SetReconciliation(b bool)
- func (pg *Page) Static(name string) DOM
- type PageCreator
- type PageNotification
- type PageSession
- type PageSessionManager
- func (psm *PageSessionManager) GetName() string
- func (psm *PageSessionManager) NewSession(t sabuhp.Transport) (*Page, string, error)
- func (psm *PageSessionManager) Retire(sessionId string) error
- func (psm *PageSessionManager) Session(sessionId string) (*Page, error)
- func (psm *PageSessionManager) Start()
- func (psm *PageSessionManager) Stat() (SessionStat, error)
- func (psm *PageSessionManager) Stop()
- func (psm *PageSessionManager) Wait()
- type Pages
- func (p *Pages) Add(pageName string, creatorFunc PageCreator) error
- func (p *Pages) AddOnPageRoute(cb OnPages)
- func (p *Pages) Get(pageName string) (*PageSessionManager, error)
- func (p *Pages) Handle(message *sabuhp.Message, tr sabuhp.Transport) sabuhp.MessageErr
- func (p *Pages) Has(pageName string) bool
- func (p *Pages) Stats() PagesStat
- func (p *Pages) Wait()
- type PagesStat
- type Params
- type ParamsSetter
- type SessionStat
- type Trie
- func (t *Trie) Autocomplete(prefix string, sorter NodeKeysSorter) (list []string)
- func (t *Trie) HasPrefix(prefix string) bool
- func (t *Trie) Insert(pattern string, options ...InsertOption)
- func (t *Trie) Parents(prefix string) (parents []*Node)
- func (t *Trie) Search(q string, params ParamsSetter) *Node
- func (t *Trie) SearchPrefix(prefix string) *Node
Constants ¶
const ( PlainHTML = "text/html" VoidHTML = "application/groundlayer+html" VoidHTMLDiff = "application/groundlayer+html+diff" VoidJSON = "application/groundlayer+json" VoidJSONStream = "application/groundlayer+json_stream" )
const ( DefaultMaxPageIdleness = 5 * time.Minute DefaultPageIdlenessChecksInterval = 2 * time.Minute HeaderSessionIdName = "X-Void-Id" QueryAndCookieSessionIdName = "_groundlayer_id" )
const ( // ParamStart is the character, as a string, which a path pattern starts to define its named parameter. ParamStart = ":" // WildcardParamStart is the character, as a string, // which a path pattern starts to define its named parameter for wildcards. // It allows everything else after that path prefix // but the Trie checks for static paths and named parameters before that in order // to support everything that other implementations do not, // and if nothing else found then it tries to find the closest wildcard path(super and unique). WildcardParamStart = "*" )
Variables ¶
var DefaultKeysSorter = func(list []string) func(i, j int) bool { return func(i, j int) bool { return len(strings.Split(list[i], pathSep)) < len(strings.Split(list[j], pathSep)) } }
DefaultKeysSorter sorts as: first the "key (the path)" with the lowest number of slashes.
Functions ¶
Types ¶
type DOMFunc ¶
type DOMRegistry ¶
type DOMRegistry struct {
// contains filtered or unexported fields
}
DOMRegistry implements the a component single for DOM objects.
func NewDOMRegistry ¶
func NewDOMRegistry() *DOMRegistry
func (*DOMRegistry) Add ¶
func (k *DOMRegistry) Add(km DOM, refName string)
Add adds giving component into underline register using the type routePath for giving component.
func (*DOMRegistry) AddList ¶
func (k *DOMRegistry) AddList(km []DOM, refName string)
AddList adds giving component into underline register using the type routePath for giving component.
func (*DOMRegistry) Clean ¶
func (k *DOMRegistry) Clean(max time.Duration)
Clean up all LiveDOM elements with a dormancy equal or above provided duration.
func (*DOMRegistry) Delete ¶
func (k *DOMRegistry) Delete(refName string)
Delete deletes any key in the singles map.
func (*DOMRegistry) DeleteList ¶
func (k *DOMRegistry) DeleteList(refName string)
DeleteList deletes any key in the list map.
func (*DOMRegistry) Get ¶
func (k *DOMRegistry) Get(refName string) DOM
Get returns the DOM matching giving type routePath.
func (*DOMRegistry) GetList ¶
func (k *DOMRegistry) GetList(refName string) []DOM
GetList returns the DOM matching giving type routePath.
func (*DOMRegistry) Has ¶
func (k *DOMRegistry) Has(refName string) bool
HasType returns true/false if giving typeName exists.
func (*DOMRegistry) HasList ¶
func (k *DOMRegistry) HasList(refName string) bool
HasType returns true/false if giving typeName exists.
func (*DOMRegistry) Reset ¶
func (k *DOMRegistry) Reset()
type DOMSet ¶
type DOMSet []DOM
DOMSet defines a list of DOM items.
type DefaultNotFound ¶
type DefaultNotFound struct{}
type Handler ¶
func LiveDOMHandler ¶
LiveDOMHandler returns a Handler which provides the params as the data to be giving to a Live DOM render method.
func StaticDOMHandler ¶
StaticDOMHandler returns a Handler which provides the params as the data to be giving to a Live DOM render method.
type HandlerFunc ¶
type InsertOption ¶
type InsertOption func(*Node)
InsertOption is just a function which accepts a pointer to a Node which can alt its `Handler`, `Tag` and `Data` fields.
See `WithTransportResponse`, `WithTag` and `WithData`.
func WithData ¶
func WithData(data interface{}) InsertOption
WithData sets the node's optionally `Data` field.
func WithHandler ¶
func WithHandler(handler Handler) InsertOption
WithHandler sets the node's `Handler` field (useful for HTTP).
func WithTag ¶
func WithTag(tag string) InsertOption
WithTag sets the node's `Tag` field (may be useful for HTTP).
func WithTransportResponse ¶
func WithTransportResponse(handler Handler) InsertOption
WithTransportResponse sets the node's `Handler` field (useful for HTTP).
type LayoutFunc ¶
type LiveDOM ¶
type LiveDOM struct {
// contains filtered or unexported fields
}
LiveDOM wraps a dom which keeps track of Last render and reconciling new renderings with the old.
func NewLiveDOM ¶
NewLiveDOM returns a DOM wrapped to return Nodes reconciled with their previous render.
func (*LiveDOM) LastCalled ¶
LastCalled returns the time when the Last called was made.
type LiveDOMList ¶
type LiveDOMList []LiveDOM
type Mux ¶
type Mux struct { NotFound Handler // contains filtered or unexported fields }
Mux is Request multiplexer. It matches an event routePath or http url pattern to a specific TransportHandler which will be registered to the provided transport for handling specific events.
type Node ¶
type Node struct { // insert main data relative to http and a tag for things like route names. Handler Handler Tag string // other insert data. Data interface{} // contains filtered or unexported fields }
Node is the trie's node which path patterns with their data like an HTTP handler are saved to. See `Trie` too.
func (*Node) Keys ¶
func (n *Node) Keys(sorter NodeKeysSorter) (list []string)
Keys returns this node's key (if it's a final path segment) and its children's node's key. The "sorter" can be optionally used to sort the result.
type NodeKeysSorter ¶
NodeKeysSorter is the type definition for the sorting logic that caller can pass on `GetKeys` and `Autocomplete`.
type Page ¶
type Page struct { UseChanges bool Name string RoutePath string AnyRouteInPage string Router *Mux Layout Layout Last *domu.Node Registry *DOMRegistry LiveRegistry *DOMRegistry LiveRouteMapping *plain.StringMap // contains filtered or unexported fields }
Page implements the Document interface and represents a single unique html page.
func NewPageUsingRouter ¶
func (*Page) AddLive ¶
AddLive returns a new live DOM by creating a route mapping between a target component or list of components in the page to be serviceable by the route ensuring it's always reconciled with it's last state.
func (*Page) AddStatic ¶
AddStatic adds a new routePath mapping for a provided list, ensuring these are referenced with giving component, if there is more than 1 item then they are treated as a whole and referenced by provided routePath.
Note: It clears all live routes for this giving routePath, if we are replacing an existing live key.
func (*Page) Cleanup ¶
Cleanup goes through the live instance releasing any which may have surpassed the maxLastUsed period.
func (*Page) GetRouting ¶
GetRouting returns the route for giving routePath.
func (*Page) HasLive ¶
HasLive returns true if giving route exists either as a live dom or dom list.
func (*Page) HasStatic ¶
HasStatic returns true if giving route exists either as a static dom or dom list.
func (*Page) Render ¶
Render renders new domu.Node from existing page which is reconciled with it's previous render.
The markup node is pure, which means it's the complete picture generated from a Page object.
func (*Page) Retire ¶
Retire retires the dom (live or static) associated with the routePath and every route associated with it.
func (*Page) ServeStatic ¶
func (*Page) SetReconciliation ¶
type PageNotification ¶ added in v0.0.6
type PageNotification struct {
// contains filtered or unexported fields
}
func NewPageNotification ¶ added in v0.0.6
func NewPageNotification() *PageNotification
func (*PageNotification) Add ¶ added in v0.0.6
func (h *PageNotification) Add(eventHandler OnPage)
func (*PageNotification) Emit ¶ added in v0.0.6
func (h *PageNotification) Emit(route string, page *Page)
type PageSession ¶
func (*PageSession) Close ¶
func (ps *PageSession) Close()
type PageSessionManager ¶
type PageSessionManager struct { Creator PageCreator // contains filtered or unexported fields }
func NewPageSessionManager ¶
func NewPageSessionManager( ctx context.Context, routePath string, maxIdle time.Duration, idleCheckInterval time.Duration, creator PageCreator, onAddRoute OnPage, ) *PageSessionManager
func (*PageSessionManager) GetName ¶
func (psm *PageSessionManager) GetName() string
func (*PageSessionManager) NewSession ¶
NewSession returns a new session page and session id.
func (*PageSessionManager) Retire ¶
func (psm *PageSessionManager) Retire(sessionId string) error
Retire returns closes a specific session using giving id.
func (*PageSessionManager) Session ¶
func (psm *PageSessionManager) Session(sessionId string) (*Page, error)
Session returns a giving page for a giving sessionId.
func (*PageSessionManager) Start ¶
func (psm *PageSessionManager) Start()
func (*PageSessionManager) Stat ¶
func (psm *PageSessionManager) Stat() (SessionStat, error)
func (*PageSessionManager) Stop ¶
func (psm *PageSessionManager) Stop()
func (*PageSessionManager) Wait ¶
func (psm *PageSessionManager) Wait()
type Pages ¶
type Pages struct {
// contains filtered or unexported fields
}
Pages exists to provider an organization around sessions and pages.
It implements the http.Handler interface.
func (*Pages) Add ¶
func (p *Pages) Add(pageName string, creatorFunc PageCreator) error
AddCreator adds a new PageCreator for a giving page routePath. It returns true/false based on whether the routePath and creator was registered or if there was routePath conflict.
func (*Pages) AddOnPageRoute ¶ added in v0.0.6
func (*Pages) Get ¶
func (p *Pages) Get(pageName string) (*PageSessionManager, error)
GetManager returns page creator registered for a giving page page
type PagesStat ¶
type PagesStat struct { TotalPages int PageSessions map[string]SessionStat }
type Params ¶
func (Params) EncodeObject ¶
func (h Params) EncodeObject(encoder npkg.ObjectEncoder)
type ParamsSetter ¶
ParamsSetter is the interface which should be implemented by the params writer for `Search` in order to store the found named path parameters, if any.
type SessionStat ¶
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
Trie contains the main logic for adding and searching nodes for path segments. It supports wildcard and named path parameters. Trie supports very coblex and useful path patterns for routes. The Trie checks for static paths(path without : or *) and named parameters before that in order to support everything that other implementations do not, and if nothing else found then it tries to find the closest wildcard path(super and unique).
func NewTrie ¶
func NewTrie() *Trie
NewTrie returns a new, empty Trie. It is only useful for end-developers that want to design their own mux/router based on my trie implementation.
See `Trie`
func (*Trie) Autocomplete ¶
func (t *Trie) Autocomplete(prefix string, sorter NodeKeysSorter) (list []string)
Autocomplete returns the keys that starts with "prefix", this is useful for custom search-engines built on top of my trie implementation.
func (*Trie) Insert ¶
func (t *Trie) Insert(pattern string, options ...InsertOption)
Insert adds a node to the trie.
func (*Trie) Search ¶
func (t *Trie) Search(q string, params ParamsSetter) *Node
Search is the most important part of the Trie. It will try to find the responsible node for a specific query (or a request path for HTTP endpoints).
Search supports searching for static paths(path without : or *) and paths that contain named parameters or wildcards. Priority as: 1. static paths 2. named parameters with ":" 3. wildcards 4. closest wildcard if not found, if any 5. rootPath wildcard
func (*Trie) SearchPrefix ¶
SearchPrefix returns the last node which holds the key which starts with "prefix".