Documentation ¶
Overview ¶
Package web provides HTML generation functions and HTTP session management.
Index ¶
- Variables
- func BaseReferer(req *http.Request) string
- func CompactCSS(css []byte) []byte
- func FormatURL(url string) string
- func HTML(content ...interface{}) []byte
- func MediaType(name string) string
- func SetClass(add bool, input string, classes ...string) string
- func SetUseNthChild(val bool)
- func UseNthChild() bool
- type Attribute
- func Attr(name, val string) Attribute
- func Charset(locale string) Attribute
- func Class(classList ...string) Attribute
- func Content(locale string) Attribute
- func HREF(href string) Attribute
- func ID(locale string) Attribute
- func Lang(locale string) Attribute
- func Name(locale string) Attribute
- func OnClick(jsCall string) Attribute
- func OnLoad(jsCall string) Attribute
- func Type(locale string) Attribute
- type Buffer
- func A(href string, content ...interface{}) *Buffer
- func Article(content ...interface{}) *Buffer
- func Body(content ...interface{}) *Buffer
- func Br(attributes ...Attribute) *Buffer
- func COLUMNS(cols []string, class string, useNthChild bool) *Buffer
- func CSS(styles ...string) *Buffer
- func Comment(s string) *Buffer
- func Container(elementName string, content ...interface{}) *Buffer
- func Div(content ...interface{}) *Buffer
- func Element(elementName string, attributes ...Attribute) *Buffer
- func Embed(html string) Buffer
- func Form(content ...interface{}) *Buffer
- func H1(content ...interface{}) *Buffer
- func H2(content ...interface{}) *Buffer
- func H3(content ...interface{}) *Buffer
- func H4(content ...interface{}) *Buffer
- func H5(content ...interface{}) *Buffer
- func H6(content ...interface{}) *Buffer
- func Head(content ...interface{}) *Buffer
- func Header(content ...interface{}) *Buffer
- func Hr(attributes ...Attribute) *Buffer
- func IFrame(content ...interface{}) *Buffer
- func Img(content ...interface{}) *Buffer
- func Input(attributes ...Attribute) *Buffer
- func JOIN(content ...*Buffer) *Buffer
- func JS(scripts ...string) *Buffer
- func Label(content ...interface{}) *Buffer
- func Li(content ...interface{}) *Buffer
- func Meta(attributes ...Attribute) *Buffer
- func MetaCharset(locale string) *Buffer
- func MetaViewport() *Buffer
- func NAV(href string, content ...interface{}) *Buffer
- func Nav(content ...interface{}) *Buffer
- func NewBuffer(size int) Buffer
- func P(content ...interface{}) *Buffer
- func Span(content ...interface{}) *Buffer
- func TEXT(texts ...string) *Buffer
- func Title(content ...interface{}) *Buffer
- func Ul(content ...interface{}) *Buffer
- type Context
- func (ctx *Context) BaseReferer() string
- func (ctx *Context) DebugString() string
- func (ctx *Context) HREF() string
- func (ctx *Context) Method() string
- func (ctx *Context) PostData() []byte
- func (ctx *Context) Redirect(url string)
- func (ctx *Context) Referer() string
- func (ctx *Context) Reply(data []byte, mediaType string)
- func (ctx *Context) ResetPostData()
- func (ctx *Context) URI() string
- type Session
- type Sessions
Constants ¶
This section is empty.
Variables ¶
var ( // PL is fmt.Println() but is used only for debugging. PL = fmt.Println // VL is zr.VerboseLog() but is used only for debugging. VL = zr.VerboseLog )
var ContextDebugFunc func(a ...interface{}) (n int, err error)
ContextDebugFunc specifies a function for testing or debugging all HTTP traffic received and sent by Context. It is called when a request is received, and when a reply is sent.
During normal program operation it should not be assigned to avoid serious security and performance issues.
To print to the console, assign fmt.Print to it, or use your own custom function if you need to log the output elsewhere
The return values are not used, just specified to match fmt.Print ¶
During normal opration, remove the followig assignment ---> = fmt.Print
var MediaTypes = []struct { ext string mimeType string }{} // MediaTypes /* 507 elements not displayed */
MediaTypes holds an array of file extensions and corresponding Internet media types (MIME type i.e. Multipurpose Internet Mail Extensions)
Functions ¶
func CompactCSS ¶
CompactCSS removes all comments, empty lines and indentation from CSS bytes.
func FormatURL ¶
FormatURL trims spaces, trailing '#', '/', and '?' from url. It also replaces backslashes '\' with forward slashes '/'. Note: this function does not perform escaping.
func HTML ¶
func HTML(content ...interface{}) []byte
HTML tag is the root of an HTML document and the top-level container for all other HTML tags. Attributes: manifest, xmlns
func MediaType ¶
MediaType returns the appropriate Internet MIME type given a file extension, file name or full MIME type. (When given a file name, it checks the ending of the given file name)
func SetClass ¶
SetClass appends or removes the specified class(es) to the given string. 'add' specifies if the class should be added (or removed if false).
'input' is the existing class string. 'classes' is a list of class names to add or remove. Returns the input string with the required classes added or removed.
Types ¶
type Attribute ¶
Attribute holds the name and value of a single HTML attribute.
type Buffer ¶
type Buffer struct { // contains filtered or unexported fields } // Buffer
Buffer represents a buffer holding HTML output.
func A ¶
A tag specifies a hyperlink, which links other web pages and locations in the current document. Attributes: charset coords download href hreflang media name rel rev shape target type
func Article ¶
func Article(content ...interface{}) *Buffer
Article defines self-contained content. Attributes: Global, Event
func Body ¶
func Body(content ...interface{}) *Buffer
Body tag: contains the visible content of a page, including text, images, hyperlinks, etc. Attributes: alink, background, bgcolor, link, text, vlink
func Br ¶
Br tag inserts a line break. This tag has no closing tag and is not a container. Attributes: Global, Event
func COLUMNS ¶
COLUMNS creates a group of <p> tags with class c1, c2, c3, etc. for every string passed in 'columns'. Used to create tabular listings using CSS and <p> tags, without the need to use HTML tables.
func CSS ¶
CSS links or embeds one or more CSS (Cascading Style Sheet) files or scripts.
To link to a CSS file, just specify the filename in 'styles', for example: CSS("global_style.css")
To embed a style locally, specify the style in styles, for example, CSS("body { font: normal 11pt Helvetica }")
Should be placed within the <head> element under <html>.
func Div ¶
func Div(content ...interface{}) *Buffer
Div tag defines an arbitrary division in the document. Attributes: align (left, right, center, justify)
func H1 ¶
func H1(content ...interface{}) *Buffer
H1 tag specifies headings (level 1) Attributes: align (left, center, right, justify)
func H2 ¶
func H2(content ...interface{}) *Buffer
H2 tag specifies headings (level 2) Attributes: align (left, center, right, justify)
func H3 ¶
func H3(content ...interface{}) *Buffer
H3 tag specifies headings (level 3) Attributes: align (left, center, right, justify)
func H4 ¶
func H4(content ...interface{}) *Buffer
H4 tag specifies headings (level 4) Attributes: align (left, center, right, justify)
func H5 ¶
func H5(content ...interface{}) *Buffer
H5 tag specifies headings (level 5) Attributes: align (left, center, right, justify)
func H6 ¶
func H6(content ...interface{}) *Buffer
H6 tag specifies headings (level 6) Attributes: align (left, center, right, justify)
func Head ¶
func Head(content ...interface{}) *Buffer
Head element is the container for a page's head elements, including the title, scripts and metadata. Allowed child elements: <base> <link> <meta> <noscript> <script> <style> <title> (required)
func Header ¶
func Header(content ...interface{}) *Buffer
Header tag contains the headings of a section or navigational links.
func Hr ¶
Hr tag inserts a thematic break (horizontal rule pre-HTML5). This tag has no closing tag and is not a container. Attributes: Global, Event
func IFrame ¶
func IFrame(content ...interface{}) *Buffer
IFrame represents an <iframe> tag, i.e. inline frame.
func Img ¶
func Img(content ...interface{}) *Buffer
Img inserts an image element. For example Img("folder/filename.png") will become <img src="folder/filename.png"> in the output HTML
func Input ¶
Input tag represents an element for user input. This tag has no closing tag and is not a container.
func JOIN ¶
JOIN concatenates the content of multiple buffers into a single buffer. It can be useful to merge together several HTML elements, with one element listed after the other.
func Li ¶
func Li(content ...interface{}) *Buffer
Li tag defines a list item in unordered (ul), ordered (ol) or menu lists (menu). Attributes: global attributes and value.
func MetaCharset ¶
MetaCharset attribute applies to <meta> tags.
func MetaViewport ¶
func MetaViewport() *Buffer
MetaViewport meta tag: enables a web page to have a responsive layout.
func NAV ¶
NAV helper tag specifies a hyperlink, which links other web pages and locations in the current document. It is similar to the 'A' tag, but uses zr.go() in JS to save the current page reference. Attributes: charset coords download href hreflang
media name rel rev shape target type
func Nav ¶
func Nav(content ...interface{}) *Buffer
Nav tag defines a section with navigation links.
func NewBuffer ¶
NewBuffer creates and initializes a new Buffer of the specified size. It is intended to prepare a buffer for writing HTML markup. In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.
func P ¶
func P(content ...interface{}) *Buffer
P tag defines a paragraph. Attribute: align, global attributes
func TEXT ¶
TEXT helper tag is a non-standard tag that helps inject literal strings into HTML content.
func Title ¶
func Title(content ...interface{}) *Buffer
Title tag specifies the title or name of the document. It is required to be placed within the <head> element.
func Ul ¶
func Ul(content ...interface{}) *Buffer
Ul defines an unordered list. (A list in which the ordering of items is not important). The list can contain zero or more <li> elements.
func (*Buffer) Reset ¶
func (ob *Buffer) Reset()
Reset makes the buffer empty, but retains allocated storage for future reuse.
func (*Buffer) String ¶
String returns the contents of the buffer as a string and implements the fmt.Stringer interface.
func (*Buffer) WriteBytes ¶
WriteBytes writes a string to the buffer.
func (*Buffer) WriteString ¶
WriteString writes a string to the buffer.
type Context ¶
type Context struct { Session *Session // contains filtered or unexported fields } // Context
Context structure wraps a HTTP request and attaches a Session object to allow state to be maintained between requests.
func NewContext ¶
NewContext creates a new Context object by wrapping a response writer (w) and request (req) from ListenAndServe() and attaching a new or existing session using 'sess'. Sessions uses cookies to determine if the request is a new session, or a previously started session.
func (*Context) BaseReferer ¶
BaseReferer property returns the base referer path of the current request. I.e. a path with '/', '\', '#' and numbers stripped from the end.
func (*Context) HREF ¶
HREF property returns the URL path of the current request. This property does not return the query parameters.
func (*Context) Redirect ¶
Redirect redirects the client to another url using HTTP redirect code 302 (temporary redirect).
func (*Context) Reply ¶
Reply method sends the reply to a request. Specify 'mediaType' to set 'Content-Type' in the HTTP header. The media type can be a file extension, such as 'pdf' or 'png' in which case it gets converted to a proper MIME type, e.g. 'application/pdf' or 'image/png' Use the file extension value, e.g. "pdf"
type Session ¶
type Session struct { // contains filtered or unexported fields } // Session
Session _ _
func (*Session) SetSetting ¶
SetSetting _ _
type Sessions ¶
type Sessions struct { // contains filtered or unexported fields } // Sessions
Sessions _ _
func (*Sessions) GetByCookie ¶
GetByCookie _ _