Documentation ¶
Index ¶
- func Find(template []byte) (places []int)
- func FindAndReplace(template []byte, wr io.Writer, replacements map[string]io.ReadSeeker)
- func FindAndReplaceBytes(template []byte, wr io.Writer, replacements map[string][]byte)
- func FindAndReplaceMapper(template []byte, bf Buffer, mapper Mapper)
- func FindAndReplaceString(template []byte, bf Buffer, replacements map[string]string)
- func Replace(template []byte, wr io.Writer, places []int, ...)
- func ReplaceBytes(template []byte, wr io.Writer, places []int, replacements map[string][]byte)
- func ReplaceMapper(template []byte, bf Buffer, places []int, mapper Mapper)
- func ReplaceString(template []byte, bf Buffer, places []int, replacements map[string]string)
- type Buffer
- type Mapper
- type Template
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Find ¶
Find looks for placeholders written in the style "<@placeholdername@>" inside the given template. It returns a slice containing the positions of the placeholders that is meant to be passed to Replace or ReplaceString.
func FindAndReplace ¶
FindAndReplace finds placeholders and replaces them in one go.
func FindAndReplaceBytes ¶
FindAndReplaceBytes finds placeholders and replaces them in one go.
func FindAndReplaceMapper ¶
FindAndReplaceMapper finds placeholders and replaces them in one go.
func FindAndReplaceString ¶
FindAndReplaceString finds placeholders and replaces them in one go.
func Replace ¶
Replace replaces the placeholders at the given places inside the template with the replacements found inside the map and writes the result to the buffer. The given template must be the unchanged byte array that was passed to Find in order to get the places. For strings as replacements see the optimized ReplaceString function for bytes use ReplaceBytes.
func ReplaceBytes ¶
ReplaceBytes replaces the placeholders at the given places inside the template with the replacements found inside the map and writes the result to the buffer. The given template must be the unchanged byte array that was passed to Find in order to get the places.
func ReplaceMapper ¶
ReplaceMapper replaces the placeholders at the given places inside the template with the replacements returned from the mapper and writes the result to the buffer. The given template must be the unchanged byte array that was passed to Find in order to get the places.
func ReplaceString ¶
ReplaceString replaces the placeholders at the given places inside the template with the replacements found inside the map and writes the result to the buffer. The given template must be the unchanged byte array that was passed to Find in order to get the places.
Types ¶
type Buffer ¶
The Buffer interface is fullfilled by *bytes.Buffer. However since for performance reasons the errors from writing to the buffer are always ignored, you will need to write a buffer wrapper to capture them.
type Mapper ¶
type Mapper interface { // Map maps a placeholder to a value. It should return the empty string, if // a value could not be found Map(string) string }
Mapper maps strings.
type Template ¶
type Template struct {
// contains filtered or unexported fields
}