-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.go
39 lines (31 loc) · 845 Bytes
/
io.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package grouter
import (
"bytes"
"fmt"
)
type TemplateValues map[string]any
type BufferedResponse struct {
buf bytes.Buffer
templateName string
values TemplateValues
end bool
}
func (r *BufferedResponse) RenderTemplate(name string, values TemplateValues, end bool) {
r.templateName = name
r.values = values
r.end = end
r.buf.Reset()
}
func (r *BufferedResponse) RenderContinueTemplate(name string, values TemplateValues) {
r.RenderTemplate(name, values, false)
}
func (r *BufferedResponse) RenderEndTemplate(name string, values TemplateValues) {
r.RenderTemplate(name, values, false)
}
func (r *BufferedResponse) Write(p []byte) (int, error) {
r.templateName = ""
return r.buf.Write(p)
}
func (r *BufferedResponse) Printf(format string, args ...any) {
_, _ = fmt.Fprintf(&r.buf, format, args...)
}