MCPcopy
hub / github.com/caddyserver/caddy / funcReadFile

Method funcReadFile

modules/caddyhttp/templates/tplcontext.go:136–147  ·  view source on GitHub ↗

funcReadFile returns the contents of a filename relative to the site root. Note that included files are NOT escaped, so you should only include trusted files. If it is not trusted, be sure to use escaping functions in your template.

(filename string)

Source from the content-addressed store, hash-verified

134// trusted files. If it is not trusted, be sure to use escaping functions
135// in your template.
136func (c TemplateContext) funcReadFile(filename string) (string, error) {
137 bodyBuf := bufPool.Get().(*bytes.Buffer)
138 bodyBuf.Reset()
139 defer bufPool.Put(bodyBuf)
140
141 err := c.readFileToBuffer(filename, bodyBuf)
142 if err != nil {
143 return "", err
144 }
145
146 return bodyBuf.String(), nil
147}
148
149// readFileToBuffer reads a file into a buffer
150func (c TemplateContext) readFileToBuffer(filename string, bodyBuf *bytes.Buffer) error {

Callers

nothing calls this directly

Calls 4

readFileToBufferMethod · 0.95
GetMethod · 0.65
ResetMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected