grender: github.com/dannyvankooten/grender Index | Files

package grender

import "github.com/dannyvankooten/grender"

Index

Package Files

buffer.go grender.go template.go

Constants

const (
    // ContentHTML HTTP header value for HTML data
    ContentHTML = "text/html"

    // ContentJSON HTTP header value for JSON data
    ContentJSON = "application/json"

    // ContentType HTTP header name for defining the content type
    ContentType = "Content-Type"

    // ContentText header value for Text data.
    ContentText = "text/plain"

    // ContentXML header value for XML data.
    ContentXML = "text/xml"

    // DefaultCharset for when no specific Charset Options was given
    DefaultCharset = "UTF-8"
)

type BufferPool Uses

type BufferPool struct {
    // contains filtered or unexported fields
}

BufferPool implements a pool of bytes.Buffers in the form of a bounded channel. Pulled from the github.com/oxtoacart/bpool package (Apache licensed).

func NewBufferPool Uses

func NewBufferPool(size int) (bp *BufferPool)

NewBufferPool creates a new BufferPool bounded to the given size.

func (*BufferPool) Get Uses

func (bp *BufferPool) Get() (b *bytes.Buffer)

Get gets a Buffer from the BufferPool, or creates a new one if none are available in the pool.

func (*BufferPool) Put Uses

func (bp *BufferPool) Put(b *bytes.Buffer)

Put returns the given Buffer to the BufferPool.

type Grender Uses

type Grender struct {
    Options   Options
    Templates templates
}

Grender provides functions for easily writing HTML templates & JSON out to a HTTP Response.

func New Uses

func New(optsarg ...Options) *Grender

New creates a new Renderer with the given Options

func (*Grender) HTML Uses

func (r *Grender) HTML(w http.ResponseWriter, statusCode int, templateName string, data interface{}) error

HTML executes the template and writes to the responsewriter

func (*Grender) JSON Uses

func (r *Grender) JSON(w http.ResponseWriter, statusCode int, data interface{}) error

JSON renders the data as a JSON HTTP response to the ResponseWriter

func (*Grender) Text Uses

func (r *Grender) Text(w http.ResponseWriter, statusCode int, data string) error

Text writes the data as a JSON HTTP response to the ResponseWriter

func (*Grender) XML Uses

func (r *Grender) XML(w http.ResponseWriter, statusCode int, data interface{}) error

XML writes the data as a XML HTTP response to the ResponseWriter

type Options Uses

type Options struct {
    // With Debug set to true, templates will be recompiled before every render call.
    Debug bool

    // The glob string to your templates
    TemplatesGlob string

    // The Glob string for additional templates
    PartialsGlob string

    // The function map to pass to each HTML template
    Funcs template.FuncMap

    // Charset for responses
    Charset string
}

Options holds the configuration Options for a Renderer

Package grender imports 10 packages (graph). Updated 2018-09-24. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).