Documentation ¶
Overview ¶
Package replacer performs fast replacements of placeholders in a []byte. It has no logic and no escaping.
For the typical scenario - your template never changes on runtime -, replacer is faster than using (strings|bytes).Replace() or regexp.ReplaceAllStringFunc() or the text/template package.
You might run the benchmarks in the benchmark directory and have a look at the example directory.
Index ¶
- func BytesMap(in map[string][]byte) map[Placeholder][]byte
- func MapHandlers(pairs ...interface{}) map[string]http.Handler
- func MapStrings(pairs ...string) map[Placeholder]string
- func StringsMap(in map[string]string) map[Placeholder]string
- type Place
- type Placeholder
- type Places
- type Setter
- type Template
- func (t *Template) NewHandler(m map[string]http.Handler) http.Handler
- func (t *Template) NewSetter() *Setter
- func (r *Template) Placeholders() (p []Placeholder)
- func (r *Template) ReplaceBytes(replacements map[Placeholder][]byte) (res []byte)
- func (r *Template) ReplaceStrings(replacements map[Placeholder]string) (res []byte)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MapHandlers ¶
func MapStrings ¶
func MapStrings(pairs ...string) map[Placeholder]string
func StringsMap ¶
func StringsMap(in map[string]string) map[Placeholder]string
Types ¶
type Place ¶
type Place struct { Pos int Placeholder Placeholder }
type Placeholder ¶
type Placeholder string
func (Placeholder) Name ¶
func (p Placeholder) Name() string
func (Placeholder) String ¶
func (p Placeholder) String() string
type Setter ¶
type Setter struct {
// contains filtered or unexported fields
}
func (*Setter) SetBytes ¶
func (i *Setter) SetBytes(ph Placeholder, b []byte)
func (*Setter) SetString ¶
func (i *Setter) SetString(ph Placeholder, s string)
type Template ¶
func NewTemplateBytes ¶
func NewTemplateString ¶
func (*Template) Placeholders ¶
func (r *Template) Placeholders() (p []Placeholder)
func (*Template) ReplaceBytes ¶
func (r *Template) ReplaceBytes(replacements map[Placeholder][]byte) (res []byte)
func (*Template) ReplaceStrings ¶
func (r *Template) ReplaceStrings(replacements map[Placeholder]string) (res []byte)
Click to show internal directories.
Click to hide internal directories.