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)
| 134 | // trusted files. If it is not trusted, be sure to use escaping functions |
| 135 | // in your template. |
| 136 | func (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 |
| 150 | func (c TemplateContext) readFileToBuffer(filename string, bodyBuf *bytes.Buffer) error { |
nothing calls this directly
no test coverage detected