Documentation ¶
Overview ¶
Package jaws provides a mechanism to create dynamic webpages using Javascript and WebSockets.
It integrates well with Go's html/template package, but can be used without it. It can be used with any router that supports the standard ServeHTTP interface.
Index ¶
- Constants
- Variables
- func AppendID(b []byte) []byte
- func HeadHTML(js []string, css []string) string
- func HtmlInner(jid jid.Jid, tag, typ string, inner template.HTML, attrs ...string) template.HTML
- func HtmlInput(jid jid.Jid, typ, val string, attrs ...string) template.HTML
- func HtmlSelect(jid jid.Jid, nba *NamedBoolArray, attrs ...string) template.HTML
- func JawsKeyString(jawsKey uint64) string
- func JawsKeyValue(jawsKey string) uint64
- func ListMove[T comparable](l []T, elem T, steps int) (changed bool)
- func ListOrder[T comparable](l []T, jw *Jaws)
- func ListRemove[T comparable](l []T, e T) []T
- func MakeID() string
- func MustTagExpand(rq *Request, tag interface{}) []interface{}
- func NextID() uint64
- func TagExpand(rq *Request, tag interface{}) ([]interface{}, error)
- func TagString(tag interface{}) string
- func WriteHtmlInner(w io.Writer, jid jid.Jid, tag, typ string, inner template.HTML, ...) (err error)
- func WriteHtmlInput(w io.Writer, jid jid.Jid, typ, val string, attrs ...string) (err error)
- func WriteHtmlSelect(w io.Writer, jid jid.Jid, nba *NamedBoolArray, attrs ...string) (err error)
- type BoolGetter
- type BoolSetter
- type ClickFndeprecated
- type ClickHandler
- type ConnectFn
- type Container
- type Element
- func (e *Element) Append(htmlCode template.HTML)
- func (e *Element) Delete()
- func (e *Element) HasTag(tag interface{}) bool
- func (e *Element) Jid() jid.Jid
- func (e *Element) Order(jidList []jid.Jid)
- func (e *Element) Remove(htmlId string)
- func (e *Element) RemoveAttr(attr string)
- func (e *Element) RemoveClass(cls string)
- func (e *Element) Render(w io.Writer, params []interface{})
- func (e *Element) Replace(htmlCode template.HTML)
- func (e *Element) SetAttr(attr, val string)
- func (e *Element) SetClass(cls string)
- func (e *Element) SetInner(innerHtml template.HTML)
- func (e *Element) SetValue(val string)
- func (e *Element) String() string
- func (e *Element) Tag(tags ...interface{})
- func (e *Element) Ui() UI
- type EventFn
- type EventHandler
- type FloatGetter
- type FloatSetter
- type HtmlGetter
- type InputBoolFndeprecated
- type InputDateFndeprecated
- type InputFloatFndeprecated
- type InputTextFndeprecated
- type Jaws
- func (jw *Jaws) Alert(lvl, msg string)
- func (jw *Jaws) Append(target interface{}, html template.HTML)
- func (jw *Jaws) Broadcast(msg Message)
- func (jw *Jaws) Close()
- func (jw *Jaws) Delete(target interface{})
- func (jw *Jaws) Dirty(tags ...interface{})
- func (jw *Jaws) Done() <-chan struct{}
- func (jw *Jaws) GenerateHeadHTML(extra ...string) error
- func (jw *Jaws) GetSession(hr *http.Request) (sess *Session)
- func (jw *Jaws) Insert(target interface{}, where, html string)
- func (jw *Jaws) Log(err error) error
- func (jw *Jaws) MustLog(err error)
- func (jw *Jaws) NewRequest(hr *http.Request) (rq *Request)
- func (jw *Jaws) NewSession(w http.ResponseWriter, hr *http.Request) (sess *Session)
- func (jw *Jaws) Order(tags []interface{})
- func (jw *Jaws) Pending() (n int)
- func (jw *Jaws) Redirect(url string)
- func (jw *Jaws) Reload()
- func (jw *Jaws) RemoveAttr(target interface{}, attr string)
- func (jw *Jaws) RemoveClass(target interface{}, cls string)
- func (jw *Jaws) Replace(target interface{}, where, html string)
- func (jw *Jaws) RequestCount() (n int)
- func (jw *Jaws) Serve()
- func (jw *Jaws) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (jw *Jaws) ServeWithTimeout(requestTimeout time.Duration)
- func (jw *Jaws) SessionCount() (n int)
- func (jw *Jaws) Sessions() (sl []*Session)
- func (jw *Jaws) SetAttr(target interface{}, attr, val string)
- func (jw *Jaws) SetClass(target interface{}, cls string)
- func (jw *Jaws) SetInner(target interface{}, innerHtml template.HTML)
- func (jw *Jaws) SetValue(target interface{}, val string)
- func (jw *Jaws) UseRequest(jawsKey uint64, hr *http.Request) (rq *Request)
- type Jid
- type Message
- type NamedBool
- func (nb *NamedBool) Array() *NamedBoolArray
- func (nb *NamedBool) Checked() (checked bool)
- func (nb *NamedBool) Html() (h template.HTML)
- func (nb *NamedBool) JawsGetBool(*Element) (v bool)
- func (nb *NamedBool) JawsGetHtml(*Element) (h template.HTML)
- func (nb *NamedBool) JawsGetString(*Element) (name string)
- func (nb *NamedBool) JawsSetBool(e *Element, checked bool) (err error)
- func (nb *NamedBool) Name() (s string)
- func (nb *NamedBool) Set(checked bool) (changed bool)
- func (nb *NamedBool) String() string
- type NamedBoolArray
- func (nba *NamedBoolArray) Add(name string, text template.HTML) *NamedBoolArray
- func (nba *NamedBoolArray) Get() (name string)
- func (nba *NamedBoolArray) IsChecked(name string) (state bool)
- func (nba *NamedBoolArray) JawsContains(rq *Request) (contents []UI)
- func (nba *NamedBoolArray) JawsGetString(e *Element) string
- func (nba *NamedBoolArray) JawsSetString(e *Element, name string) (err error)
- func (nba *NamedBoolArray) ReadLocked(fn func(nbl []*NamedBool))
- func (nba *NamedBoolArray) Set(name string, state bool) (changed bool)
- func (nba *NamedBoolArray) String() string
- func (nba *NamedBoolArray) WriteLocked(fn func(nbl []*NamedBool) []*NamedBool)
- type RadioElement
- type Request
- func (rq *Request) A(innerHtml interface{}, params ...interface{}) template.HTML
- func (rq *Request) Alert(lvl, msg string)
- func (rq *Request) AlertError(err error)
- func (rq *Request) Button(innerHtml interface{}, params ...interface{}) template.HTML
- func (rq *Request) Checkbox(value interface{}, params ...interface{}) template.HTML
- func (rq *Request) Container(outerHtmlTag string, c Container, params ...interface{}) template.HTML
- func (rq *Request) Context() (ctx context.Context)
- func (rq *Request) Date(value interface{}, params ...interface{}) template.HTML
- func (rq *Request) Dirty(tags ...interface{})
- func (rq *Request) Div(innerHtml interface{}, params ...interface{}) template.HTML
- func (rq *Request) Done() (ch <-chan struct{})
- func (rq *Request) Get(key string) interface{}
- func (rq *Request) GetConnectFn() (fn ConnectFn)
- func (rq *Request) GetElement(jid Jid) (e *Element)
- func (rq *Request) GetElements(tag interface{}) (elems []*Element)
- func (rq *Request) HasTag(elem *Element, tag interface{}) (yes bool)
- func (rq *Request) HeadHTML() template.HTML
- func (rq *Request) Img(imageSrc interface{}, params ...interface{}) template.HTML
- func (rq *Request) JawsKeyString() string
- func (rq *Request) JawsRender(elem *Element, w io.Writer, params []interface{})
- func (rq *Request) Label(innerHtml interface{}, params ...interface{}) template.HTML
- func (rq *Request) Li(innerHtml interface{}, params ...interface{}) template.HTML
- func (rq *Request) MakeTemplate(templ, dot interface{}) Template
- func (rq *Request) MustTemplate(v interface{}) (tp *template.Template)
- func (rq *Request) NewElement(ui UI) *Element
- func (rq *Request) Number(value interface{}, params ...interface{}) template.HTML
- func (rq *Request) Password(value interface{}, params ...interface{}) template.HTML
- func (rq *Request) Radio(value interface{}, params ...interface{}) template.HTML
- func (rq *Request) RadioGroup(nba *NamedBoolArray) (rl []RadioElement)
- func (rq *Request) Range(value interface{}, params ...interface{}) template.HTML
- func (rq *Request) Redirect(url string)
- func (rq *Request) Register(tagitem interface{}, params ...interface{}) jid.Jid
- func (rq *Request) Select(sh SelectHandler, params ...interface{}) template.HTML
- func (rq *Request) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (rq *Request) Session() *Session
- func (rq *Request) Set(key string, val interface{})
- func (rq *Request) SetConnectFn(fn ConnectFn)
- func (rq *Request) Span(innerHtml interface{}, params ...interface{}) template.HTML
- func (rq *Request) String() string
- func (rq *Request) Tag(elem *Element, tags ...interface{})
- func (rq *Request) TagsOf(elem *Element) (tags []interface{})
- func (rq *Request) Tbody(c Container, params ...interface{}) template.HTML
- func (rq *Request) Td(innerHtml interface{}, params ...interface{}) template.HTML
- func (rq *Request) Template(templ, dot interface{}, params ...interface{}) template.HTML
- func (rq *Request) Text(value interface{}, params ...interface{}) template.HTML
- func (rq *Request) Textarea(value interface{}, params ...interface{}) template.HTML
- func (rq *Request) Tr(innerHtml interface{}, params ...interface{}) template.HTML
- func (rq *Request) UI(ui UI, params ...interface{}) template.HTML
- type SelectHandler
- type Session
- func (sess *Session) Broadcast(msg Message)
- func (sess *Session) Clear()
- func (sess *Session) Close() (cookie *http.Cookie)
- func (sess *Session) Cookie() (cookie *http.Cookie)
- func (sess *Session) CookieValue() (s string)
- func (sess *Session) Get(key string) (val interface{})
- func (sess *Session) ID() (id uint64)
- func (sess *Session) IP() (ip net.IP)
- func (sess *Session) Reload()
- func (sess *Session) Set(key string, val interface{})
- type StringGetter
- type StringSetter
- type Tag
- type TagGetter
- type Template
- type TimeGetter
- type TimeSetter
- type UI
- type Uideprecated
- type UiA
- type UiButton
- type UiCheckbox
- type UiContainer
- type UiDate
- type UiDiv
- type UiHtml
- type UiHtmlInner
- type UiImg
- type UiInput
- type UiInputBool
- type UiInputDate
- type UiInputFloat
- type UiInputText
- type UiLabel
- type UiLi
- type UiNumber
- type UiOption
- type UiPassword
- type UiRadio
- type UiRange
- type UiSelect
- type UiSpan
- type UiTbody
- type UiTd
- type UiTemplate
- type UiText
- type UiTextarea
- type UiTr
- type With
Constants ¶
const ( DefaultCookieName = "jaws" // Default browser cookie name DefaultUpdateInterval = time.Millisecond * 100 // Default browser update interval )
const ISO8601 = "2006-01-02"
Variables ¶
var ErrEventUnhandled = errEventUnhandled{}
ErrEventUnhandled returned by JawsEvent() or JawsClick() causes the next available handler to be invoked.
var ErrIllegalTagType = errIllegalTagType{}
var ErrNoWebSocketRequest = errors.New("no WebSocket request received")
var ErrTooManyTags = errTooManyTags{}
var ErrWebsocketQueueOverflow = errors.New("websocket queue overflow")
var JavascriptGZip = makeJavascriptGZip()
JavascriptGZip is the embedded Javascript library GZipped.
var JavascriptPath = makeJavascriptPath()
JavascriptPath is the path for the embedded JaWS Javascript library.
var JavascriptText []byte
JavascriptText is the source code for the client-side JaWS Javascript library.
Functions ¶
func AppendID ¶ added in v0.31.0
AppendID appends the result of NextID() in text form to the given slice.
func HtmlSelect ¶ added in v0.2.13
func JawsKeyString ¶
JawsKeyString returns the string to be used for the given JaWS key.
func JawsKeyValue ¶ added in v0.11.0
JawsKeyValue parses a key string (as returned JawsKeyString) into a uint64.
func ListMove ¶ added in v0.31.0
func ListMove[T comparable](l []T, elem T, steps int) (changed bool)
func ListOrder ¶ added in v0.31.0
func ListOrder[T comparable](l []T, jw *Jaws)
func ListRemove ¶ added in v0.31.0
func ListRemove[T comparable](l []T, e T) []T
func MakeID ¶ added in v0.24.0
func MakeID() string
MakeID returns a string in the form 'jaws.X' where X is a unique string within lifetime of the program.
func MustTagExpand ¶ added in v0.34.0
func MustTagExpand(rq *Request, tag interface{}) []interface{}
func NextID ¶ added in v0.31.0
func NextID() uint64
NextID returns a uint64 unique within lifetime of the program.
func WriteHtmlInner ¶ added in v0.31.0
func WriteHtmlInput ¶ added in v0.31.0
func WriteHtmlSelect ¶ added in v0.31.0
Types ¶
type BoolGetter ¶ added in v0.31.0
type BoolSetter ¶ added in v0.31.0
type BoolSetter interface { BoolGetter JawsSetBool(rq *Element, v bool) (err error) }
type ClickHandler ¶ added in v0.31.0
type ConnectFn ¶
ConnectFn can be used to interact with a Request before message processing starts. Returning an error causes the Request to abort, and the WebSocket connection to close.
type Element ¶ added in v0.31.0
type Element struct { *Request // (read-only) the Request the Element belongs to // contains filtered or unexported fields }
An Element is an instance of a *Request, an UI object and a Jid.
func (*Element) Append ¶ added in v0.31.0
Append appends a new HTML element as a child to the current one.
Call this only during JawsRender() or JawsUpdate() processing.
func (*Element) Delete ¶ added in v0.31.0
func (e *Element) Delete()
Delete requests that this Element is removed from the Request and it's HTML element from the browser.
Call this only during JawsRender() or JawsUpdate() processing.
func (*Element) Jid ¶ added in v0.31.0
Jid returns the JaWS ID for this Element, unique within it's Request.
func (*Element) Order ¶ added in v0.31.0
Order reorders the HTML elements.
Call this only during JawsRender() or JawsUpdate() processing.
func (*Element) Remove ¶ added in v0.31.0
Remove requests that the HTML child with the given HTML ID of this Element is removed from the Request and it's HTML element from the browser.
Call this only during JawsRender() or JawsUpdate() processing.
func (*Element) RemoveAttr ¶ added in v0.31.0
RemoveAttr queues sending a request to remove an attribute to the browser for the Element with the given JaWS ID in this Request.
Call this only during JawsRender() or JawsUpdate() processing.
func (*Element) RemoveClass ¶ added in v0.31.0
RemoveClass queues sending a request to remove a class to the browser for the Element with the given JaWS ID in this Request.
Call this only during JawsRender() or JawsUpdate() processing.
func (*Element) Replace ¶ added in v0.31.0
Replace replaces the elements entire HTML DOM node with new HTML code. If the HTML code doesn't seem to contain correct HTML ID, it panics.
Call this only during JawsRender() or JawsUpdate() processing.
func (*Element) SetAttr ¶ added in v0.31.0
SetAttr queues sending a new attribute value to the browser for the Element with the given JaWS ID in this Request.
Call this only during JawsRender() or JawsUpdate() processing.
func (*Element) SetClass ¶ added in v0.31.0
SetClass a queues sending a class to the browser for the Element with the given JaWS ID in this Request.
Call this only during JawsRender() or JawsUpdate() processing.
func (*Element) SetInner ¶ added in v0.31.0
SetInner queues sending a new inner HTML content to the browser for the Element.
Call this only during JawsRender() or JawsUpdate() processing.
func (*Element) SetValue ¶ added in v0.31.0
SetValue queues sending a new current input value in textual form to the browser for the Element with the given JaWS ID in this Request.
Call this only during JawsRender() or JawsUpdate() processing.
type EventFn ¶
EventFn is the signature of a event handling function to be called when JaWS receives an event message from the Javascript via the WebSocket connection.
type EventHandler ¶ added in v0.31.0
type FloatGetter ¶ added in v0.31.0
type FloatSetter ¶ added in v0.31.0
type FloatSetter interface { FloatGetter JawsSetFloat(e *Element, v float64) (err error) }
type HtmlGetter ¶ added in v0.31.0
type InputBoolFn
deprecated
type InputFloatFn
deprecated
type InputTextFn
deprecated
type Jaws ¶
type Jaws struct { CookieName string // Name for session cookies, defaults to "jaws" Logger *log.Logger // If not nil, send debug info and errors here Template *template.Template // User templates in use, may be nil Debug bool // set to true to enable debugging output // contains filtered or unexported fields }
func New ¶
func New() (jw *Jaws)
New returns a new JaWS object that must be closed using Close(). This is expected to be created once per HTTP server and handles publishing HTML changes across all connections.
func NewWithDone ¶
func NewWithDone(doneCh <-chan struct{}) *Jaws
NewWithDone returns a new JaWS object using the given completion channel. This is expected to be created once per HTTP server and handles publishing HTML changes across all connections.
func (*Jaws) Alert ¶
Alert sends an alert to all Requests. The lvl argument should be one of Bootstraps alert levels: primary, secondary, success, danger, warning, info, light or dark.
func (*Jaws) Append ¶
Append calls the Javascript 'appendChild()' method on all HTML elements matching target.
func (*Jaws) Close ¶
func (jw *Jaws) Close()
Close frees resources associated with the JaWS object, and closes the completion channel if the JaWS was created with New(). Once the completion channel is closed, broadcasts and sends may be discarded. Subsequent calls to Close() have no effect.
func (*Jaws) Delete ¶ added in v0.31.0
func (jw *Jaws) Delete(target interface{})
Delete removes the HTML element(s) matching target.
func (*Jaws) Dirty ¶ added in v0.31.0
func (jw *Jaws) Dirty(tags ...interface{})
Dirty marks all Elements that have one or more of the given tags as dirty.
Note that if any of the tags are a TagGetter, it will be called with a nil Request. Prefer using Request.Dirty() which avoids this.
func (*Jaws) GenerateHeadHTML ¶ added in v0.5.0
GenerateHeadHTML (re-)generates the HTML code that goes in the HEAD section, ensuring that the provided scripts and stylesheets in `extra` are loaded.
You only need to call this if you want to add your own scripts and stylesheets.
func (*Jaws) GetSession ¶ added in v0.11.0
GetSession returns the Session associated with the given *http.Request, or nil.
func (*Jaws) Insert ¶
Insert calls the Javascript 'insertBefore()' method on all HTML elements matching target.
The position parameter 'where' may be either a HTML ID, an child index or the text 'null'.
func (*Jaws) Log ¶
Log sends an error to the Logger set in the Jaws. Has no effect if the err is nil or the Logger is nil. Returns err.
func (*Jaws) MustLog ¶ added in v0.1.1
MustLog sends an error to the Logger set in the Jaws or panics with the given error if no Logger is set. Has no effect if the err is nil.
func (*Jaws) NewRequest ¶
NewRequest returns a new pending JaWS request that times out after 10 seconds.
Call this as soon as you start processing a HTML request, and store the returned Request pointer so it can be used while constructing the HTML response in order to register the JaWS id's you use in the response, and use it's Key attribute when sending the Javascript portion of the reply.
func (*Jaws) NewSession ¶ added in v0.26.0
NewSession creates a new Session.
Any pre-existing Session will be cleared and closed.
Subsequent Requests created with `NewRequest()` that have the cookie set and originates from the same IP will be able to access the Session.
func (*Jaws) Order ¶ added in v0.31.0
func (jw *Jaws) Order(tags []interface{})
Order re-orders HTML elements matching the given tags in all Requests.
func (*Jaws) Reload ¶
func (jw *Jaws) Reload()
Reload requests all Requests to reload their current page.
func (*Jaws) RemoveAttr ¶
RemoveAttr sends a request to remove the given attribute from all HTML elements matching target.
func (*Jaws) RemoveClass ¶ added in v0.31.0
RemoveClass sends a request to remove the given class from all HTML elements matching target.
func (*Jaws) Replace ¶
Replace replaces the HTML content on all HTML elements matching target.
The position parameter 'where' may be either a HTML ID or an index.
func (*Jaws) RequestCount ¶ added in v0.25.0
RequestCount returns the number of active and pending Requests.
"Active" Requests are those for which there is a WebSocket connection and messages are being routed for. "Pending" are those for which the initial HTTP request has been made but we have not yet received the WebSocket callback and started processing.
func (*Jaws) ServeHTTP ¶ added in v0.19.0
func (jw *Jaws) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP can handle the required JaWS endpoints, which all start with "/jaws/".
func (*Jaws) ServeWithTimeout ¶
ServeWithTimeout begins processing requests with the given timeout. It is intended to run on it's own goroutine. It returns when the completion channel is closed.
func (*Jaws) SessionCount ¶ added in v0.11.0
SessionCount returns the number of active sessions.
func (*Jaws) Sessions ¶ added in v0.11.0
Sessions returns a list of all active sessions, which may be nil.
func (*Jaws) SetAttr ¶
SetAttr sends a request to replace the given attribute value in all HTML elements matching target.
func (*Jaws) SetClass ¶ added in v0.31.0
SetClass sends a request to set the given class in all HTML elements matching target.
func (*Jaws) SetInner ¶
SetInner sends a request to replace the inner HTML of all HTML elements matching target.
func (*Jaws) SetValue ¶
SetValue sends a request to set the HTML "value" attribute of all HTML elements matching target.
func (*Jaws) UseRequest ¶
UseRequest extracts the JaWS request with the given key from the request map if it exists and the HTTP request remote IP matches.
Call it when receiving the WebSocket connection on '/jaws/:key' to get the associated Request, and then call it's ServeHTTP method to process the WebSocket messages.
Returns nil if the key was not found or the IP doesn't match, in which case you should return a HTTP "404 Not Found" status.
type Message ¶
type Message struct { Dest interface{} // destination (tag, html ID or *Element) What what.What // what to change or do Data interface{} // data (e.g. inner HTML content or slice of tags) }
Message contains the elements of a message to be sent to Requests.
type NamedBool ¶
type NamedBool struct {
// contains filtered or unexported fields
}
NamedBool stores a named boolen value with a HTML representation.
func NewNamedBool ¶ added in v0.31.0
func (*NamedBool) Array ¶ added in v0.31.0
func (nb *NamedBool) Array() *NamedBoolArray
func (*NamedBool) JawsGetBool ¶ added in v0.31.0
func (*NamedBool) JawsGetHtml ¶ added in v0.31.0
func (*NamedBool) JawsGetString ¶ added in v0.31.0
func (*NamedBool) JawsSetBool ¶ added in v0.31.0
type NamedBoolArray ¶
type NamedBoolArray struct { Multi bool // allow multiple NamedBools to be true // contains filtered or unexported fields }
NamedBoolArray stores the data required to support HTML 'select' elements and sets of HTML radio buttons. It it safe to use from multiple goroutines concurrently.
func NewNamedBoolArray ¶
func NewNamedBoolArray() *NamedBoolArray
NewNamedBoolArray creates a new object to track a related set of named booleans.
The JaWS ID string 'jid' is used as the ID for <select> elements and the value for the 'name' attribute for radio buttons. If left empty, MakeID() will be used to assign a unique ID.
func (*NamedBoolArray) Add ¶
func (nba *NamedBoolArray) Add(name string, text template.HTML) *NamedBoolArray
Add adds a NamedBool with the given name and the given text. Returns itself.
Note that while it's legal to have multiple NamedBool with the same name since it's allowed in HTML, it's probably not a good idea.
func (*NamedBoolArray) Get ¶ added in v0.24.0
func (nba *NamedBoolArray) Get() (name string)
Get returns the name of first NamedBool in the group that has it's Checked value set to true. Returns an empty string if none are true.
In case you can have more than one selected or you need to distinguish between a blank name and the fact that none are set to true, use ReadLocked() to inspect the data directly.
func (*NamedBoolArray) IsChecked ¶ added in v0.24.0
func (nba *NamedBoolArray) IsChecked(name string) (state bool)
IsChecked returns true if any of the NamedBool in the set that have the given name are Checked. Returns false if the name is not found.
func (*NamedBoolArray) JawsContains ¶ added in v0.31.0
func (nba *NamedBoolArray) JawsContains(rq *Request) (contents []UI)
func (*NamedBoolArray) JawsGetString ¶ added in v0.31.0
func (nba *NamedBoolArray) JawsGetString(e *Element) string
func (*NamedBoolArray) JawsSetString ¶ added in v0.31.0
func (nba *NamedBoolArray) JawsSetString(e *Element, name string) (err error)
func (*NamedBoolArray) ReadLocked ¶ added in v0.24.0
func (nba *NamedBoolArray) ReadLocked(fn func(nbl []*NamedBool))
ReadLocked calls the given function with the NamedBoolArray locked for reading.
func (*NamedBoolArray) Set ¶
func (nba *NamedBoolArray) Set(name string, state bool) (changed bool)
Set sets the Checked state for the NamedBool(s) with the given name.
func (*NamedBoolArray) String ¶
func (nba *NamedBoolArray) String() string
String returns a string representation of the NamedBoolArray suitable for debugging.
func (*NamedBoolArray) WriteLocked ¶ added in v0.24.0
func (nba *NamedBoolArray) WriteLocked(fn func(nbl []*NamedBool) []*NamedBool)
WriteLocked calls the given function with the NamedBoolArray locked for writing and replaces the internal []*NamedBool slice with the return value.
type RadioElement ¶ added in v0.31.0
type RadioElement struct {
// contains filtered or unexported fields
}
func (*RadioElement) Label ¶ added in v0.31.0
func (r *RadioElement) Label(params ...interface{}) template.HTML
Label renders a HTML label element.
func (RadioElement) Radio ¶ added in v0.31.0
func (r RadioElement) Radio(params ...interface{}) template.HTML
Radio renders a HTML input element of type 'radio'.
type Request ¶
type Request struct { Jaws *Jaws // (read-only) the JaWS instance the Request belongs to JawsKey uint64 // (read-only) a random number used in the WebSocket URI to identify this Request Created time.Time // (read-only) when the Request was created, used for automatic cleanup Initial *http.Request // (read-only) initial HTTP request passed to Jaws.NewRequest // contains filtered or unexported fields }
Request maintains the state for a JaWS WebSocket connection, and handles processing of events and broadcasts.
Note that we have to store the context inside the struct because there is no call chain between the Request being created and it being used once the WebSocket is created.
func (*Request) Alert ¶
Alert attempts to show an alert message on the current request webpage if it has an HTML element with the id 'jaws-alert'. The lvl argument should be one of Bootstraps alert levels: primary, secondary, success, danger, warning, info, light or dark.
The default JaWS javascript only supports Bootstrap.js dismissable alerts.
func (*Request) AlertError ¶
AlertError calls Alert if the given error is not nil.
func (*Request) Context ¶
Context returns the Request's Context, which is derived from the WebSocket's HTTP requests Context.
func (*Request) Dirty ¶ added in v0.31.0
func (rq *Request) Dirty(tags ...interface{})
Dirty marks all Elements that have one or more of the given tags as dirty.
func (*Request) Done ¶ added in v0.31.0
func (rq *Request) Done() (ch <-chan struct{})
Done returns the Request completion channel.
func (*Request) Get ¶ added in v0.11.0
Get is shorthand for `Session().Get()` and returns the session value associated with the key, or nil. It no session is associated with the Request, returns nil.
func (*Request) GetConnectFn ¶ added in v0.7.0
GetConnectFn returns the currently set ConnectFn. That function will be called before starting the WebSocket tunnel if not nil.
func (*Request) GetElement ¶ added in v0.31.0
func (*Request) GetElements ¶ added in v0.31.0
GetElements returns a list of the UI elements in the Request that have the given tag.
func (*Request) HeadHTML ¶
HeadHTML returns the HTML code needed to write in the HTML page's HEAD section.
func (*Request) JawsKeyString ¶
func (*Request) JawsRender ¶ added in v0.31.0
func (*Request) MakeTemplate ¶ added in v0.31.0
func (*Request) MustTemplate ¶ added in v0.31.0
GetTemplate resolves 'v' to a *template.Template or panics.
func (*Request) NewElement ¶ added in v0.31.0
func (*Request) RadioGroup ¶ added in v0.24.0
func (rq *Request) RadioGroup(nba *NamedBoolArray) (rl []RadioElement)
func (*Request) Register ¶
Register creates a new Element with the given tagitem as a valid target for dynamic updates.
This function can accept a string or a Jid as the tagitem. A string will be interpreted as jaws.Tag(string).
Returns a Jid, suitable for including as a HTML "id" attribute:
<div id="{{$.Register `footag`}}">
func (*Request) Select ¶
func (rq *Request) Select(sh SelectHandler, params ...interface{}) template.HTML
func (*Request) ServeHTTP ¶
func (rq *Request) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.HanderFunc.
Assumes UseRequest() have been successfully called for the Request.
func (*Request) Set ¶ added in v0.11.0
Set is shorthand for `Session().Set()` and sets a session value to be associated with the key. If value is nil, the key is removed from the session. Does nothing if there is no session is associated with the Request.
func (*Request) SetConnectFn ¶ added in v0.7.0
SetConnectFn sets ConnectFn. That function will be called before starting the WebSocket tunnel if not nil.
func (*Request) Template ¶ added in v0.31.0
Template renders the given template using jaws.With{Dot: dot} as data.
The templ argument can either be a string, in which case Jaws.Template.Lookup() will be used to resolve it. Or it can be a *template.Template directly.
type SelectHandler ¶ added in v0.31.0
type SelectHandler interface { Container StringSetter }
type Session ¶ added in v0.11.0
type Session struct {
// contains filtered or unexported fields
}
func (*Session) Broadcast ¶ added in v0.26.0
Broadcast attempts to send a message to all Requests using this session. It is safe to call on a nil Session.
func (*Session) Clear ¶ added in v0.16.0
func (sess *Session) Clear()
Clear removes all key/value pairs from the session. It is safe to call on a nil Session.
func (*Session) Close ¶ added in v0.17.0
Close invalidates and expires the Session. Future Requests won't be able to associate with it, and Cookie() will return a deletion cookie.
Existing Requests already associated with the Session will ask the browser to reload the pages. Key/value pairs in the Session are left unmodified, you can use `Session.Clear()` to remove all of them.
Returns a cookie to be sent to the client browser that will delete the browser cookie. Returns nil if the session was not found or is already closed. It is safe to call on a nil Session.
func (*Session) Cookie ¶ added in v0.11.0
Cookie returns a cookie for the Session. Returns a delete cookie if the Session is expired. It is safe to call on a nil Session, in which case it returns nil.
func (*Session) CookieValue ¶ added in v0.11.0
CookieValue returns the session cookie value. It is safe to call on a nil Session, in which case it returns an empty string.
func (*Session) Get ¶ added in v0.11.0
Get returns the value associated with the key, or nil. It is safe to call on a nil Session.
func (*Session) ID ¶ added in v0.11.0
ID returns the session ID, a 64-bit random value. It is safe to call on a nil Session, in which case it returns zero.
func (*Session) IP ¶ added in v0.11.0
IP returns the remote IP the session is bound to (which may be nil). It is safe to call on a nil Session, in which case it returns nil.
type StringGetter ¶ added in v0.31.0
type StringSetter ¶ added in v0.31.0
type StringSetter interface { StringGetter JawsSetString(e *Element, v string) (err error) }
type TagGetter ¶ added in v0.31.0
type TagGetter interface {
JawsGetTag(rq *Request) interface{} // Note that the Request may be nil
}
type Template ¶ added in v0.31.0
func (Template) JawsRender ¶ added in v0.31.0
func (Template) JawsUpdate ¶ added in v0.31.0
type TimeGetter ¶ added in v0.31.0
type TimeSetter ¶ added in v0.31.0
type TimeSetter interface { TimeGetter JawsSetTime(e *Element, v time.Time) (err error) }
type UI ¶ added in v0.31.0
type UI interface { JawsRender(e *Element, w io.Writer, params []interface{}) JawsUpdate(e *Element) }
If any of these functions panic, the Request will be closed and the panic logged. Optionally you may also implement ClickHandler and/or EventHandler.
type UiA ¶ added in v0.31.0
type UiA struct {
UiHtmlInner
}
func NewUiA ¶ added in v0.31.0
func NewUiA(innerHtml HtmlGetter) *UiA
type UiButton ¶ added in v0.31.0
type UiButton struct {
UiHtmlInner
}
func NewUiButton ¶ added in v0.31.0
func NewUiButton(innerHtml HtmlGetter) *UiButton
type UiCheckbox ¶ added in v0.31.0
type UiCheckbox struct {
UiInputBool
}
func NewUiCheckbox ¶ added in v0.31.0
func NewUiCheckbox(g BoolGetter) *UiCheckbox
func (*UiCheckbox) JawsRender ¶ added in v0.31.0
func (ui *UiCheckbox) JawsRender(e *Element, w io.Writer, params []interface{})
type UiContainer ¶ added in v0.31.0
type UiContainer struct { OuterHtmlTag string // contains filtered or unexported fields }
func NewUiContainer ¶ added in v0.31.0
func NewUiContainer(outerHtmlTag string, c Container) *UiContainer
func (*UiContainer) JawsRender ¶ added in v0.31.0
func (ui *UiContainer) JawsRender(e *Element, w io.Writer, params []interface{})
func (*UiContainer) JawsUpdate ¶ added in v0.31.0
func (ui *UiContainer) JawsUpdate(e *Element)
type UiDate ¶ added in v0.31.0
type UiDate struct {
UiInputDate
}
func NewUiDate ¶ added in v0.31.0
func NewUiDate(g TimeGetter) *UiDate
type UiDiv ¶ added in v0.31.0
type UiDiv struct {
UiHtmlInner
}
func NewUiDiv ¶ added in v0.31.0
func NewUiDiv(innerHtml HtmlGetter) *UiDiv
type UiHtml ¶ added in v0.31.0
type UiHtml struct {
Tag any
}
func (*UiHtml) JawsRender ¶ added in v0.31.0
func (*UiHtml) JawsUpdate ¶ added in v0.31.0
type UiHtmlInner ¶ added in v0.31.0
type UiHtmlInner struct { UiHtml HtmlGetter }
func (*UiHtmlInner) JawsUpdate ¶ added in v0.31.0
func (ui *UiHtmlInner) JawsUpdate(e *Element)
type UiImg ¶ added in v0.31.0
type UiImg struct { UiHtml StringGetter }
func NewUiImg ¶ added in v0.31.0
func NewUiImg(g StringGetter) *UiImg
func (*UiImg) JawsRender ¶ added in v0.31.0
func (*UiImg) JawsUpdate ¶ added in v0.31.0
type UiInputBool ¶ added in v0.31.0
type UiInputBool struct { UiInput BoolGetter }
func (*UiInputBool) JawsUpdate ¶ added in v0.31.0
func (ui *UiInputBool) JawsUpdate(e *Element)
type UiInputDate ¶ added in v0.31.0
type UiInputDate struct { UiInput TimeGetter }
func (*UiInputDate) JawsUpdate ¶ added in v0.31.0
func (ui *UiInputDate) JawsUpdate(e *Element)
type UiInputFloat ¶ added in v0.31.0
type UiInputFloat struct { UiInput FloatGetter }
func (*UiInputFloat) JawsUpdate ¶ added in v0.31.0
func (ui *UiInputFloat) JawsUpdate(e *Element)
type UiInputText ¶ added in v0.31.0
type UiInputText struct { UiInput StringSetter }
func (*UiInputText) JawsUpdate ¶ added in v0.31.0
func (ui *UiInputText) JawsUpdate(e *Element)
type UiLabel ¶ added in v0.31.0
type UiLabel struct {
UiHtmlInner
}
func NewUiLabel ¶ added in v0.31.0
func NewUiLabel(innerHtml HtmlGetter) *UiLabel
type UiLi ¶ added in v0.31.0
type UiLi struct {
UiHtmlInner
}
func NewUiLi ¶ added in v0.31.0
func NewUiLi(innerHtml HtmlGetter) *UiLi
type UiNumber ¶ added in v0.31.0
type UiNumber struct {
UiInputFloat
}
func NewUiNumber ¶ added in v0.31.0
func NewUiNumber(g FloatGetter) *UiNumber
type UiOption ¶ added in v0.31.0
type UiOption struct{ *NamedBool }
func (UiOption) JawsRender ¶ added in v0.31.0
func (UiOption) JawsUpdate ¶ added in v0.31.0
type UiPassword ¶ added in v0.31.0
type UiPassword struct {
UiInputText
}
func NewUiPassword ¶ added in v0.31.0
func NewUiPassword(g StringSetter) *UiPassword
func (*UiPassword) JawsRender ¶ added in v0.31.0
func (ui *UiPassword) JawsRender(e *Element, w io.Writer, params []interface{})
type UiRadio ¶ added in v0.31.0
type UiRadio struct {
UiInputBool
}
func NewUiRadio ¶ added in v0.31.0
func NewUiRadio(vp BoolGetter) *UiRadio
type UiRange ¶ added in v0.31.0
type UiRange struct {
UiInputFloat
}
func NewUiRange ¶ added in v0.31.0
func NewUiRange(g FloatGetter) *UiRange
type UiSelect ¶ added in v0.31.0
type UiSelect struct {
// contains filtered or unexported fields
}
func NewUiSelect ¶ added in v0.31.0
func NewUiSelect(sh SelectHandler) *UiSelect
func (*UiSelect) JawsRender ¶ added in v0.31.0
func (*UiSelect) JawsUpdate ¶ added in v0.31.0
type UiSpan ¶ added in v0.31.0
type UiSpan struct {
UiHtmlInner
}
func NewUiSpan ¶ added in v0.31.0
func NewUiSpan(innerHtml HtmlGetter) *UiSpan
type UiTbody ¶ added in v0.31.0
type UiTbody struct {
// contains filtered or unexported fields
}
func NewUiTbody ¶ added in v0.31.0
func (*UiTbody) JawsRender ¶ added in v0.31.0
func (*UiTbody) JawsUpdate ¶ added in v0.31.0
func (ui *UiTbody) JawsUpdate(e *Element)
type UiTd ¶ added in v0.31.0
type UiTd struct {
UiHtmlInner
}
func NewUiTd ¶ added in v0.31.0
func NewUiTd(innerHtml HtmlGetter) *UiTd
type UiTemplate ¶ added in v0.31.0
type UiTemplate struct {
Template
}
func NewUiTemplate ¶ added in v0.31.0
func NewUiTemplate(t Template) UiTemplate
NewUiTemplate returns a UiTemplate that renders the given jaws.Template using jaws.With{Dot: dot} as data.
type UiText ¶ added in v0.31.0
type UiText struct {
UiInputText
}
func NewUiText ¶ added in v0.31.0
func NewUiText(vp StringSetter) (ui *UiText)
type UiTextarea ¶ added in v0.31.0
type UiTextarea struct {
UiInputText
}
func NewUiTextarea ¶ added in v0.31.0
func NewUiTextarea(g StringSetter) (ui *UiTextarea)
func (*UiTextarea) JawsRender ¶ added in v0.31.0
func (ui *UiTextarea) JawsRender(e *Element, w io.Writer, params []interface{})
func (*UiTextarea) JawsUpdate ¶ added in v0.31.0
func (ui *UiTextarea) JawsUpdate(e *Element)
type UiTr ¶ added in v0.31.0
type UiTr struct {
UiHtmlInner
}
func NewUiTr ¶ added in v0.31.0
func NewUiTr(innerHtml HtmlGetter) *UiTr
Source Files ¶
- atomicgetter.go
- boolgetter.go
- clickhandler.go
- container.go
- element.go
- eventhandler.go
- floatgetter.go
- html.go
- htmlgetter.go
- jaws.go
- js.go
- legacy.go
- list.go
- message.go
- namedbool.go
- namedboolarray.go
- request.go
- selecthandler.go
- servehttp.go
- session.go
- stringgetter.go
- subscription.go
- tag.go
- taggetter.go
- template.go
- timegetter.go
- ui.go
- uia.go
- uibutton.go
- uicheckbox.go
- uicontainer.go
- uidate.go
- uidiv.go
- uihtml.go
- uihtmlinner.go
- uiimg.go
- uiinput.go
- uiinputbool.go
- uiinputdate.go
- uiinputfloat.go
- uiinputtext.go
- uilabel.go
- uili.go
- uinumber.go
- uioption.go
- uipassword.go
- uiradio.go
- uiradiogroup.go
- uirange.go
- uiselect.go
- uispan.go
- uitbody.go
- uitd.go
- uitemplate.go
- uitext.go
- uitextarea.go
- uitr.go
- uiwrapcontainer.go
- with.go
- ws.go
- wsmsg.go