MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / ExecuteFunc

Method ExecuteFunc

pkg/util/fasttemplate/template.go:123–148  ·  view source on GitHub ↗

ExecuteFunc calls f on each template tag (placeholder) occurrence. Returns the number of bytes written to w. This function is optimized for frozen templates. Use ExecuteFunc for constantly changing templates.

(w io.Writer, f TagFunc)

Source from the content-addressed store, hash-verified

121// This function is optimized for frozen templates.
122// Use ExecuteFunc for constantly changing templates.
123func (t *Template) ExecuteFunc(w io.Writer, f TagFunc) (int64, error) {
124 var nn int64
125
126 n := len(t.texts) - 1
127 if n == -1 {
128 ni, err := w.Write(stringToBytes(t.template))
129 return int64(ni), err
130 }
131
132 for i := 0; i < n; i++ {
133 ni, err := w.Write(t.texts[i])
134 nn += int64(ni)
135 if err != nil {
136 return nn, err
137 }
138
139 ni, err = f(w, t.tags[i])
140 nn += int64(ni)
141 if err != nil {
142 return nn, err
143 }
144 }
145 ni, err := w.Write(t.texts[n])
146 nn += int64(ni)
147 return nn, err
148}
149
150// Execute substitutes template tags (placeholders) with the corresponding
151// values from the map m and writes the result to the given writer w.

Callers 3

ExecuteMethod · 0.95
ExecuteFuncStringMethod · 0.95
FormatMethod · 0.80

Calls 2

stringToBytesFunction · 0.85
WriteMethod · 0.65

Tested by

no test coverage detected