示例#1
0
package core

import (
	"github.com/karlseguin/bytepool"
	"io"
)

var BytePool = bytepool.New(128, 4096)

// cache interface
type Cache interface {
	Get(key string) Code
	Set(key string, template Code)
	Clear()
}

// The callback to execute to resolve include tags
// If you're going to use name to read from the filesystem, beware of directory
// traversal.
type IncludeHandler func(name string, writer io.Writer, data map[string]interface{})

// Configuration used for generating a template
type Configuration struct {
	cache              Cache
	includeHandler     IncludeHandler
	preserveWhitespace bool
}

// Set the caching engine, or nil for no caching
func (c *Configuration) Cache(cache Cache) *Configuration {
	c.cache = cache
示例#2
0
// Occasionally, Liquid needs to create temporary buffers (supporting the
// capture tag, for example). It uses a fixed-length byte pool. You can control
// the number of buffers to keep in the pool as well as the maximum size of each
// item. By default, 512 items are kept with a maximum of 4KB. If you expect
// large captures, you should increase the size parameter
func (c *Configuration) SetInternalBuffer(count, size int) *Configuration {
	c.bytepool = bytepool.New(count, size)
	return c
}
示例#3
0
// Set's the count and size of the internal bytepool
func SetInternalBuffer(count, size int) {
	core.BytePool = bytepool.New(count, size)
}
示例#4
0
package core

import (
	"github.com/karlseguin/bytepool"
)

var BytePool = bytepool.New(64, 65536)
示例#5
0
// more than a little ugly...
func InitInvalidPool(poolSize, bufferSize int) {
	invalidBytePool = bytepool.New(poolSize, bufferSize)
}
示例#6
0
package validation

import (
	"fmt"
	"github.com/karlseguin/bytepool"
	"net/http"
	"strconv"
)

var invalidBytePool = bytepool.New(1, 1024)

// more than a little ugly...
func InitInvalidPool(poolSize, bufferSize int) {
	invalidBytePool = bytepool.New(poolSize, bufferSize)
}

type InvalidResponse struct {
	buffer *bytepool.Item
}

func NewResponse(errors map[string][]*Definition) *InvalidResponse {
	buffer := invalidBytePool.Checkout()
	//am I really doing this in a public repo?!
	buffer.WriteByte(byte('{'))
	for field, definitions := range errors {
		buffer.WriteString(fmt.Sprintf("%q:[", field))
		for _, definition := range definitions {
			buffer.WriteString(fmt.Sprintf("%q,", definition.message))
		}
		buffer.Position(buffer.Len() - 1) //strip trailing comma
		buffer.WriteString("],")
示例#7
0
func newRouter(c *Configuration) *Router {
	bp := bytepool.New(c.bodyPoolSize, int(c.maxBodySize))
	return &Router{c, bp}
}