| 1 | // Copyright 2015 Matthew Holt and The Caddy Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package templatesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/ |
| 16 | |
| 17 | import ( |
| 18 | "bytesscip-go gomod github.com/golang/go/src go1.25.1 bytes/" |
| 19 | "fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/" |
| 20 | "ioscip-go gomod github.com/golang/go/src go1.25.1 io/" |
| 21 | "io/fsscip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/" |
| 22 | "netscip-go gomod github.com/golang/go/src go1.25.1 net/" |
| 23 | "net/httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/" |
| 24 | "net/urlscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/" |
| 25 | "osscip-go gomod github.com/golang/go/src go1.25.1 os/" |
| 26 | "pathscip-go gomod github.com/golang/go/src go1.25.1 path/" |
| 27 | "reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/" |
| 28 | "strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/" |
| 29 | "stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/" |
| 30 | "syncscip-go gomod github.com/golang/go/src go1.25.1 sync/" |
| 31 | "text/templatescip-go gomod github.com/golang/go/src go1.25.1 `text/template`/" |
| 32 | "timescip-go gomod github.com/golang/go/src go1.25.1 time/" |
| 33 | |
| 34 | "github.com/Masterminds/sprig/v3scip-go gomod github.com/Masterminds/sprig/v3 v3.3.0 `github.com/Masterminds/sprig/v3`/" |
| 35 | chromahtmlscip-go gomod github.com/alecthomas/chroma/v2 v2.24.1 `github.com/alecthomas/chroma/v2/formatters/html`/ "github.com/alecthomas/chroma/v2/formatters/htmlscip-go gomod github.com/alecthomas/chroma/v2 v2.24.1 `github.com/alecthomas/chroma/v2/formatters/html`/" |
| 36 | "github.com/dustin/go-humanizescip-go gomod github.com/dustin/go-humanize v1.0.1 `github.com/dustin/go-humanize`/" |
| 37 | "github.com/yuin/goldmarkscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark`/" |
| 38 | highlightingscip-go gomod github.com/yuin/goldmark-highlighting/v2 37449abec8cc `github.com/yuin/goldmark-highlighting/v2`/ "github.com/yuin/goldmark-highlighting/v2scip-go gomod github.com/yuin/goldmark-highlighting/v2 37449abec8cc `github.com/yuin/goldmark-highlighting/v2`/" |
| 39 | "github.com/yuin/goldmark/extensionscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark/extension`/" |
| 40 | "github.com/yuin/goldmark/parserscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark/parser`/" |
| 41 | gmhtmlscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark/renderer/html`/ "github.com/yuin/goldmark/renderer/htmlscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark/renderer/html`/" |
| 42 | "go.uber.org/zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/" |
| 43 | |
| 44 | "github.com/caddyserver/caddy/v2scip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/" |
| 45 | "github.com/caddyserver/caddy/v2/modules/caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/" |
| 46 | ) |
| 47 | |
| 48 | // TemplateContext is the TemplateContext with which HTTP templates are executed. |
| 49 | type TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext# struct { |
| 50 | Rootscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Root. httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.FileSystemscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/FileSystem# |
| 51 | Reqscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Req. *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request# |
| 52 | Argsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Args. []any // defined by arguments to funcInclude |
| 53 | RespHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#RespHeader. WrappedHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/WrappedHeader# |
| 54 | CustomFuncsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#CustomFuncs. []templatescip-go gomod github.com/golang/go/src go1.25.1 `text/template`/.FuncMapscip-go gomod github.com/golang/go/src go1.25.1 `text/template`/FuncMap# // functions added by plugins |
| 55 | |
| 56 | configscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#config. *Templatesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/Templates# |
| 57 | tplscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#tpl. *templatescip-go gomod github.com/golang/go/src go1.25.1 `text/template`/.Templatescip-go gomod github.com/golang/go/src go1.25.1 `text/template`/Template# |
| 58 | } |
| 59 | |
| 60 | // NewTemplate returns a new template intended to be evaluated with this |
| 61 | // context, as it is initialized with configuration from this context. |
| 62 | func (c *TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) NewTemplatescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#NewTemplate().(tplName string) *templatescip-go gomod github.com/golang/go/src go1.25.1 `text/template`/.Templatescip-go gomod github.com/golang/go/src go1.25.1 `text/template`/Template# { |
| 63 | c.tplscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#tpl. = templatescip-go gomod github.com/golang/go/src go1.25.1 `text/template`/.Newscip-go gomod github.com/golang/go/src go1.25.1 `text/template`/New().(tplName).Optionscip-go gomod github.com/golang/go/src go1.25.1 `text/template`/Template#Option().("missingkey=zero") |
| 64 | |
| 65 | // customize delimiters, if applicable |
| 66 | if c.configscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#config. != nil && len(c.configscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#config..Delimitersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/Templates#Delimiters.) == 2 { |
| 67 | c.tplscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#tpl..Delimsscip-go gomod github.com/golang/go/src go1.25.1 `text/template`/Template#Delims().(c.configscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#config..Delimitersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/Templates#Delimiters.[0], c.configscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#config..Delimitersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/Templates#Delimiters.[1]) |
| 68 | } |
| 69 | |
| 70 | // add sprig library |
| 71 | c.tplscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#tpl..Funcsscip-go gomod github.com/golang/go/src go1.25.1 `text/template`/Template#Funcs().(sprigFuncMapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/sprigFuncMap.) |
| 72 | |
| 73 | // add all custom functions |
| 74 | for _, funcMap := range c.CustomFuncsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#CustomFuncs. { |
| 75 | c.tplscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#tpl..Funcsscip-go gomod github.com/golang/go/src go1.25.1 `text/template`/Template#Funcs().(funcMap) |
| 76 | } |
| 77 | |
| 78 | // add our own library |
| 79 | c.tplscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#tpl..Funcsscip-go gomod github.com/golang/go/src go1.25.1 `text/template`/Template#Funcs().(templatescip-go gomod github.com/golang/go/src go1.25.1 `text/template`/.FuncMapscip-go gomod github.com/golang/go/src go1.25.1 `text/template`/FuncMap#{ |
| 80 | "include": c.funcIncludescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcInclude()., |
| 81 | "readFile": c.funcReadFilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcReadFile()., |
| 82 | "import": c.funcImportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcImport()., |
| 83 | "httpInclude": c.funcHTTPIncludescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcHTTPInclude()., |
| 84 | "stripHTML": c.funcStripHTMLscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcStripHTML()., |
| 85 | "markdown": c.funcMarkdownscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcMarkdown()., |
| 86 | "splitFrontMatter": c.funcSplitFrontMatterscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcSplitFrontMatter()., |
| 87 | "listFiles": c.funcListFilesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcListFiles()., |
| 88 | "fileStat": c.funcFileStatscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcFileStat()., |
| 89 | "env": c.funcEnvscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcEnv()., |
| 90 | "placeholder": c.funcPlaceholderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcPlaceholder()., |
| 91 | "ph": c.funcPlaceholderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcPlaceholder()., // shortcut |
| 92 | "fileExists": c.funcFileExistsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcFileExists()., |
| 93 | "httpError": c.funcHTTPErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcHTTPError()., |
| 94 | "humanize": c.funcHumanizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcHumanize()., |
| 95 | "maybe": c.funcMaybescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcMaybe()., |
| 96 | "pathEscape": urlscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/.PathEscapescip-go gomod github.com/golang/go/src go1.25.1 `net/url`/PathEscape()., |
| 97 | }) |
| 98 | return c.tplscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#tpl. |
| 99 | } |
| 100 | |
| 101 | // OriginalReq returns the original, unmodified, un-rewritten request as |
| 102 | // it originally came in over the wire. |
| 103 | func (c TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) OriginalReqscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#OriginalReq().() httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request# { |
| 104 | or, _ := c.Reqscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Req..Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().().Valuescip-go gomod github.com/golang/go/src go1.25.1 context/Context#Value().(caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.OriginalRequestCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/OriginalRequestCtxKey.).(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) |
| 105 | return or |
| 106 | } |
| 107 | |
| 108 | // funcInclude returns the contents of filename relative to the site root and renders it in place. |
| 109 | // Note that included files are NOT escaped, so you should only include |
| 110 | // trusted files. If it is not trusted, be sure to use escaping functions |
| 111 | // in your template. |
| 112 | func (c TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) funcIncludescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcInclude().(filename string, args ...any) (string, error) { |
| 113 | bodyBuf := bufPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/bufPool..Getscip-go gomod github.com/golang/go/src go1.25.1 sync/Pool#Get().().(*bytesscip-go gomod github.com/golang/go/src go1.25.1 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#) |
| 114 | bodyBuf.Resetscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#Reset().() |
| 115 | defer bufPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/bufPool..Putscip-go gomod github.com/golang/go/src go1.25.1 sync/Pool#Put().(bodyBuf) |
| 116 | |
| 117 | err := c.readFileToBufferscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#readFileToBuffer().(filename, bodyBuf) |
| 118 | if err != nil { |
| 119 | return "", err |
| 120 | } |
| 121 | |
| 122 | c.Argsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Args. = args |
| 123 | |
| 124 | err = c.executeTemplateInBufferscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#executeTemplateInBuffer().(filename, bodyBuf) |
| 125 | if err != nil { |
| 126 | return "", err |
| 127 | } |
| 128 | |
| 129 | return bodyBuf.Stringscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#String().(), nil |
| 130 | } |
| 131 | |
| 132 | // funcReadFile returns the contents of a filename relative to the site root. |
| 133 | // Note that included files are NOT escaped, so you should only include |
| 134 | // trusted files. If it is not trusted, be sure to use escaping functions |
| 135 | // in your template. |
| 136 | func (c TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) funcReadFilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcReadFile().(filename string) (string, error) { |
| 137 | bodyBuf := bufPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/bufPool..Getscip-go gomod github.com/golang/go/src go1.25.1 sync/Pool#Get().().(*bytesscip-go gomod github.com/golang/go/src go1.25.1 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#) |
| 138 | bodyBuf.Resetscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#Reset().() |
| 139 | defer bufPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/bufPool..Putscip-go gomod github.com/golang/go/src go1.25.1 sync/Pool#Put().(bodyBuf) |
| 140 | |
| 141 | err := c.readFileToBufferscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#readFileToBuffer().(filename, bodyBuf) |
| 142 | if err != nil { |
| 143 | return "", err |
| 144 | } |
| 145 | |
| 146 | return bodyBuf.Stringscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#String().(), nil |
| 147 | } |
| 148 | |
| 149 | // readFileToBuffer reads a file into a buffer |
| 150 | func (c TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) readFileToBufferscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#readFileToBuffer().(filename string, bodyBuf *bytesscip-go gomod github.com/golang/go/src go1.25.1 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#) error { |
| 151 | if c.Rootscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Root. == nil { |
| 152 | return fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("root file system not specified") |
| 153 | } |
| 154 | |
| 155 | file, err := c.Rootscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Root..Openscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/FileSystem#Open().(filename) |
| 156 | if err != nil { |
| 157 | return err |
| 158 | } |
| 159 | defer file.Closescip-go gomod github.com/golang/go/src go1.25.1 io/Closer#Close().() |
| 160 | |
| 161 | _, err = ioscip-go gomod github.com/golang/go/src go1.25.1 io/.Copyscip-go gomod github.com/golang/go/src go1.25.1 io/Copy().(bodyBuf, file) |
| 162 | if err != nil { |
| 163 | return err |
| 164 | } |
| 165 | |
| 166 | return nil |
| 167 | } |
| 168 | |
| 169 | // funcHTTPInclude returns the body of a virtual (lightweight) request |
| 170 | // to the given URI on the same server. Note that included bodies |
| 171 | // are NOT escaped, so you should only include trusted resources. |
| 172 | // If it is not trusted, be sure to use escaping functions yourself. |
| 173 | func (c TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) funcHTTPIncludescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcHTTPInclude().(uri string) (string, error) { |
| 174 | // prevent virtual request loops by counting how many levels |
| 175 | // deep we are; and if we get too deep, return an error |
| 176 | recursionCount := 1 |
| 177 | if numStr := c.Reqscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Req..Headerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Header..Getscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#Get().(recursionPreventionHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/recursionPreventionHeader.); numStr != "" { |
| 178 | num, err := strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.25.1 strconv/Atoi().(numStr) |
| 179 | if err != nil { |
| 180 | return "", fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("parsing %s: %v", recursionPreventionHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/recursionPreventionHeader., err) |
| 181 | } |
| 182 | if num >= 3 { |
| 183 | return "", fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("virtual request cycle") |
| 184 | } |
| 185 | recursionCount = num + 1 |
| 186 | } |
| 187 | |
| 188 | buf := bufPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/bufPool..Getscip-go gomod github.com/golang/go/src go1.25.1 sync/Pool#Get().().(*bytesscip-go gomod github.com/golang/go/src go1.25.1 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#) |
| 189 | buf.Resetscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#Reset().() |
| 190 | defer bufPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/bufPool..Putscip-go gomod github.com/golang/go/src go1.25.1 sync/Pool#Put().(buf) |
| 191 | |
| 192 | virtReq, err := httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/NewRequest().("GET", uri, nil) |
| 193 | if err != nil { |
| 194 | return "", err |
| 195 | } |
| 196 | virtReq.Hostscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Host. = c.Reqscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Req..Hostscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Host. |
| 197 | virtReq.RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. = "127.0.0.1:10000" // https://github.com/caddyserver/caddy/issues/5835 |
| 198 | virtReq.Headerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Header. = c.Reqscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Req..Headerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Header..Clonescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#Clone().() |
| 199 | virtReq.Headerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Header..Setscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#Set().("Accept-Encoding", "identity") // https://github.com/caddyserver/caddy/issues/4352 |
| 200 | virtReq.Trailerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Trailer. = c.Reqscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Req..Trailerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Trailer..Clonescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#Clone().() |
| 201 | virtReq.Headerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Header..Setscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#Set().(recursionPreventionHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/recursionPreventionHeader., strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/.Itoascip-go gomod github.com/golang/go/src go1.25.1 strconv/Itoa().(recursionCount)) |
| 202 | |
| 203 | vrw := &virtualResponseWriterscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/virtualResponseWriter#{bodyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/virtualResponseWriter#body.: buf, headerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/virtualResponseWriter#header.: make(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Headerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#)} |
| 204 | server := c.Reqscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Req..Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().().Valuescip-go gomod github.com/golang/go/src go1.25.1 context/Context#Value().(caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ServerCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ServerCtxKey.).(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Handlerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Handler#) |
| 205 | |
| 206 | server.ServeHTTPscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Handler#ServeHTTP().(vrw, virtReq) |
| 207 | if vrw.statusscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/virtualResponseWriter#status. >= 400 { |
| 208 | return "", fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("http %d", vrw.statusscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/virtualResponseWriter#status.) |
| 209 | } |
| 210 | |
| 211 | err = c.executeTemplateInBufferscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#executeTemplateInBuffer().(uri, buf) |
| 212 | if err != nil { |
| 213 | return "", err |
| 214 | } |
| 215 | |
| 216 | return buf.Stringscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#String().(), nil |
| 217 | } |
| 218 | |
| 219 | // funcImport parses the filename into the current template stack. The imported |
| 220 | // file will be rendered within the current template by calling {{ block }} or |
| 221 | // {{ template }} from the standard template library. If the imported file has |
| 222 | // no {{ define }} blocks, the name of the import will be the path |
| 223 | func (c *TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) funcImportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcImport().(filename string) (string, error) { |
| 224 | bodyBuf := bufPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/bufPool..Getscip-go gomod github.com/golang/go/src go1.25.1 sync/Pool#Get().().(*bytesscip-go gomod github.com/golang/go/src go1.25.1 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#) |
| 225 | bodyBuf.Resetscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#Reset().() |
| 226 | defer bufPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/bufPool..Putscip-go gomod github.com/golang/go/src go1.25.1 sync/Pool#Put().(bodyBuf) |
| 227 | |
| 228 | err := c.readFileToBufferscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#readFileToBuffer().(filename, bodyBuf) |
| 229 | if err != nil { |
| 230 | return "", err |
| 231 | } |
| 232 | |
| 233 | _, err = c.tplscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#tpl..Parsescip-go gomod github.com/golang/go/src go1.25.1 `text/template`/Template#Parse().(bodyBuf.Stringscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#String().()) |
| 234 | if err != nil { |
| 235 | return "", err |
| 236 | } |
| 237 | return "", nil |
| 238 | } |
| 239 | |
| 240 | func (c *TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) executeTemplateInBufferscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#executeTemplateInBuffer().(tplName string, buf *bytesscip-go gomod github.com/golang/go/src go1.25.1 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#) error { |
| 241 | c.NewTemplatescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#NewTemplate().(tplName) |
| 242 | |
| 243 | _, err := c.tplscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#tpl..Parsescip-go gomod github.com/golang/go/src go1.25.1 `text/template`/Template#Parse().(buf.Stringscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#String().()) |
| 244 | if err != nil { |
| 245 | return err |
| 246 | } |
| 247 | |
| 248 | buf.Resetscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#Reset().() // reuse buffer for output |
| 249 | |
| 250 | return c.tplscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#tpl..Executescip-go gomod github.com/golang/go/src go1.25.1 `text/template`/Template#Execute().(buf, c) |
| 251 | } |
| 252 | |
| 253 | func (c TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) funcPlaceholderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcPlaceholder().(name string) string { |
| 254 | repl := c.Reqscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Req..Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().().Valuescip-go gomod github.com/golang/go/src go1.25.1 context/Context#Value().(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ReplacerCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ReplacerCtxKey.).(*caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Replacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#) |
| 255 | |
| 256 | // For safety, we don't want to allow the file placeholder in |
| 257 | // templates because it could be used to read arbitrary files |
| 258 | // if the template contents were not trusted. |
| 259 | repl = repl.WithoutFilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#WithoutFile().() |
| 260 | |
| 261 | value, _ := repl.GetStringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#GetString().(name) |
| 262 | return value |
| 263 | } |
| 264 | |
| 265 | func (TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) funcEnvscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcEnv().(varName string) string { |
| 266 | return osscip-go gomod github.com/golang/go/src go1.25.1 os/.Getenvscip-go gomod github.com/golang/go/src go1.25.1 os/Getenv().(varName) |
| 267 | } |
| 268 | |
| 269 | // Cookie gets the value of a cookie with name. |
| 270 | func (c TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) Cookiescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Cookie().(name string) string { |
| 271 | cookies := c.Reqscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Req..Cookiesscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Cookies().() |
| 272 | for _, cookie := range cookies { |
| 273 | if cookie.Namescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Cookie#Name. == name { |
| 274 | return cookie.Valuescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Cookie#Value. |
| 275 | } |
| 276 | } |
| 277 | return "" |
| 278 | } |
| 279 | |
| 280 | // RemoteIP gets the IP address of the connection's remote IP. |
| 281 | func (c TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) RemoteIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#RemoteIP().() string { |
| 282 | ip, _, err := netscip-go gomod github.com/golang/go/src go1.25.1 net/.SplitHostPortscip-go gomod github.com/golang/go/src go1.25.1 net/SplitHostPort().(c.Reqscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Req..RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr.) |
| 283 | if err != nil { |
| 284 | return c.Reqscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Req..RemoteAddrscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#RemoteAddr. |
| 285 | } |
| 286 | return ip |
| 287 | } |
| 288 | |
| 289 | // ClientIP gets the IP address of the real client making the request |
| 290 | // if the request is trusted (see trusted_proxies), otherwise returns |
| 291 | // the connection's remote IP. |
| 292 | func (c TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) ClientIPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#ClientIP().() string { |
| 293 | address := caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.GetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/GetVar().(c.Reqscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Req..Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.ClientIPVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/ClientIPVarKey.).(string) |
| 294 | clientIP, _, err := netscip-go gomod github.com/golang/go/src go1.25.1 net/.SplitHostPortscip-go gomod github.com/golang/go/src go1.25.1 net/SplitHostPort().(address) |
| 295 | if err != nil { |
| 296 | clientIP = address // no port |
| 297 | } |
| 298 | return clientIP |
| 299 | } |
| 300 | |
| 301 | // Host returns the hostname portion of the Host header |
| 302 | // from the HTTP request. |
| 303 | func (c TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) Hostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Host().() (string, error) { |
| 304 | host, _, err := netscip-go gomod github.com/golang/go/src go1.25.1 net/.SplitHostPortscip-go gomod github.com/golang/go/src go1.25.1 net/SplitHostPort().(c.Reqscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Req..Hostscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Host.) |
| 305 | if err != nil { |
| 306 | if !stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.1 strings/Contains().(c.Reqscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Req..Hostscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Host., ":") { |
| 307 | // common with sites served on the default port 80 |
| 308 | return c.Reqscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Req..Hostscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Host., nil |
| 309 | } |
| 310 | return "", err |
| 311 | } |
| 312 | return host, nil |
| 313 | } |
| 314 | |
| 315 | // funcStripHTML returns s without HTML tags. Similar to PHP's strip_tags() |
| 316 | func (TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) funcStripHTMLscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcStripHTML().(s string) string { |
| 317 | var buf bytesscip-go gomod github.com/golang/go/src go1.25.1 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer# |
| 318 | depth := 0 |
| 319 | var quoteChar rune |
| 320 | for _, ch := range s { |
| 321 | switch { |
| 322 | case depth > 0 && quoteChar == 0 && (ch == '"' || ch == '\''): |
| 323 | // entering a quoted attribute value |
| 324 | quoteChar = ch |
| 325 | case depth > 0 && ch == quoteChar: |
| 326 | // leaving a quoted attribute value |
| 327 | quoteChar = 0 |
| 328 | case ch == '<' && quoteChar == 0: |
| 329 | depth++ |
| 330 | case ch == '>' && quoteChar == 0: |
| 331 | if depth > 0 { |
| 332 | depth-- |
| 333 | } else { |
| 334 | buf.WriteRunescip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#WriteRune().(ch) // stray '>' with no opening '<', keep it |
| 335 | } |
| 336 | default: |
| 337 | if depth == 0 { |
| 338 | buf.WriteRunescip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#WriteRune().(ch) |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return buf.Stringscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#String().() |
| 343 | } |
| 344 | |
| 345 | // funcMarkdown renders the markdown body as HTML. The resulting |
| 346 | // HTML is NOT escaped so that it can be rendered as HTML. |
| 347 | func (TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) funcMarkdownscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcMarkdown().(input any) (string, error) { |
| 348 | inputStr := caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ToStringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ToString().(input) |
| 349 | |
| 350 | md := goldmarkscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark`/.Newscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark`/New().( |
| 351 | goldmarkscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark`/.WithExtensionsscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark`/WithExtensions().( |
| 352 | extensionscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark/extension`/.GFMscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark/extension`/GFM., |
| 353 | extensionscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark/extension`/.Footnotescip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark/extension`/Footnote., |
| 354 | highlightingscip-go gomod github.com/yuin/goldmark-highlighting/v2 37449abec8cc `github.com/yuin/goldmark-highlighting/v2`/.NewHighlightingscip-go gomod github.com/yuin/goldmark-highlighting/v2 37449abec8cc `github.com/yuin/goldmark-highlighting/v2`/NewHighlighting().( |
| 355 | highlightingscip-go gomod github.com/yuin/goldmark-highlighting/v2 37449abec8cc `github.com/yuin/goldmark-highlighting/v2`/.WithFormatOptionsscip-go gomod github.com/yuin/goldmark-highlighting/v2 37449abec8cc `github.com/yuin/goldmark-highlighting/v2`/WithFormatOptions().( |
| 356 | chromahtmlscip-go gomod github.com/alecthomas/chroma/v2 v2.24.1 `github.com/alecthomas/chroma/v2/formatters/html`/.WithClassesscip-go gomod github.com/alecthomas/chroma/v2 v2.24.1 `github.com/alecthomas/chroma/v2/formatters/html`/WithClasses().(true), |
| 357 | ), |
| 358 | ), |
| 359 | ), |
| 360 | goldmarkscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark`/.WithParserOptionsscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark`/WithParserOptions().( |
| 361 | parserscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark/parser`/.WithAutoHeadingIDscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark/parser`/WithAutoHeadingID().(), |
| 362 | ), |
| 363 | goldmarkscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark`/.WithRendererOptionsscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark`/WithRendererOptions().( |
| 364 | gmhtmlscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark/renderer/html`/.WithUnsafescip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark/renderer/html`/WithUnsafe().(), // TODO: this is not awesome, maybe should be configurable? |
| 365 | ), |
| 366 | ) |
| 367 | |
| 368 | buf := bufPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/bufPool..Getscip-go gomod github.com/golang/go/src go1.25.1 sync/Pool#Get().().(*bytesscip-go gomod github.com/golang/go/src go1.25.1 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#) |
| 369 | buf.Resetscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#Reset().() |
| 370 | defer bufPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/bufPool..Putscip-go gomod github.com/golang/go/src go1.25.1 sync/Pool#Put().(buf) |
| 371 | |
| 372 | err := md.Convertscip-go gomod github.com/yuin/goldmark v1.8.2 `github.com/yuin/goldmark`/Markdown#Convert().([]byte(inputStr), buf) |
| 373 | if err != nil { |
| 374 | return "", err |
| 375 | } |
| 376 | |
| 377 | return buf.Stringscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#String().(), nil |
| 378 | } |
| 379 | |
| 380 | // funcSplitFrontMatter parses front matter out from the beginning of input, |
| 381 | // and returns the separated key-value pairs and the body/content. input |
| 382 | // must be a "stringy" value. |
| 383 | func (TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) funcSplitFrontMatterscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcSplitFrontMatter().(input any) (parsedMarkdownDocscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/parsedMarkdownDoc#, error) { |
| 384 | meta, body, err := extractFrontMatterscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/extractFrontMatter().(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ToStringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ToString().(input)) |
| 385 | if err != nil { |
| 386 | return parsedMarkdownDocscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/parsedMarkdownDoc#{}, err |
| 387 | } |
| 388 | return parsedMarkdownDocscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/parsedMarkdownDoc#{Metascip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/parsedMarkdownDoc#Meta.: meta, Bodyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/parsedMarkdownDoc#Body.: body}, nil |
| 389 | } |
| 390 | |
| 391 | // funcListFiles reads and returns a slice of names from the given |
| 392 | // directory relative to the root of c. |
| 393 | func (c TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) funcListFilesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcListFiles().(name string) ([]string, error) { |
| 394 | if c.Rootscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Root. == nil { |
| 395 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("root file system not specified") |
| 396 | } |
| 397 | |
| 398 | dir, err := c.Rootscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Root..Openscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/FileSystem#Open().(pathscip-go gomod github.com/golang/go/src go1.25.1 path/.Cleanscip-go gomod github.com/golang/go/src go1.25.1 path/Clean().(name)) |
| 399 | if err != nil { |
| 400 | return nil, err |
| 401 | } |
| 402 | defer dir.Closescip-go gomod github.com/golang/go/src go1.25.1 io/Closer#Close().() |
| 403 | |
| 404 | stat, err := dir.Statscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/File#Stat().() |
| 405 | if err != nil { |
| 406 | return nil, err |
| 407 | } |
| 408 | if !stat.IsDirscip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/FileInfo#IsDir().() { |
| 409 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("%v is not a directory", name) |
| 410 | } |
| 411 | |
| 412 | dirInfo, err := dir.Readdirscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/File#Readdir().(0) |
| 413 | if err != nil { |
| 414 | return nil, err |
| 415 | } |
| 416 | |
| 417 | names := make([]string, len(dirInfo)) |
| 418 | for i, fileInfo := range dirInfo { |
| 419 | names[i] = fileInfo.Namescip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/FileInfo#Name().() |
| 420 | } |
| 421 | |
| 422 | return names, nil |
| 423 | } |
| 424 | |
| 425 | // funcFileExists returns true if filename can be opened successfully. |
| 426 | func (c TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) funcFileExistsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcFileExists().(filename string) (bool, error) { |
| 427 | if c.Rootscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Root. == nil { |
| 428 | return false, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("root file system not specified") |
| 429 | } |
| 430 | file, err := c.Rootscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Root..Openscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/FileSystem#Open().(filename) |
| 431 | if err == nil { |
| 432 | file.Closescip-go gomod github.com/golang/go/src go1.25.1 io/Closer#Close().() |
| 433 | return true, nil |
| 434 | } |
| 435 | return false, nil |
| 436 | } |
| 437 | |
| 438 | // funcFileStat returns Stat of a filename |
| 439 | func (c TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) funcFileStatscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcFileStat().(filename string) (fsscip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/.FileInfoscip-go gomod github.com/golang/go/src go1.25.1 `io/fs`/FileInfo#, error) { |
| 440 | if c.Rootscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Root. == nil { |
| 441 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("root file system not specified") |
| 442 | } |
| 443 | |
| 444 | file, err := c.Rootscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#Root..Openscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/FileSystem#Open().(pathscip-go gomod github.com/golang/go/src go1.25.1 path/.Cleanscip-go gomod github.com/golang/go/src go1.25.1 path/Clean().(filename)) |
| 445 | if err != nil { |
| 446 | return nil, err |
| 447 | } |
| 448 | defer file.Closescip-go gomod github.com/golang/go/src go1.25.1 io/Closer#Close().() |
| 449 | |
| 450 | return file.Statscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/File#Stat().() |
| 451 | } |
| 452 | |
| 453 | // funcHTTPError returns a structured HTTP handler error. EXPERIMENTAL; SUBJECT TO CHANGE. |
| 454 | // Example usage: `{{if not (fileExists $includeFile)}}{{httpError 404}}{{end}}` |
| 455 | func (c TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) funcHTTPErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcHTTPError().(statusCode int) (bool, error) { |
| 456 | // Delete some headers that may have been set by the underlying |
| 457 | // handler (such as file_server) which may break the error response. |
| 458 | c.RespHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#RespHeader..Headerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/WrappedHeader#Header..Delscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#Del().("Content-Length") |
| 459 | c.RespHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#RespHeader..Headerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/WrappedHeader#Header..Delscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#Del().("Content-Type") |
| 460 | c.RespHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#RespHeader..Headerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/WrappedHeader#Header..Delscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#Del().("Etag") |
| 461 | c.RespHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#RespHeader..Headerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/WrappedHeader#Header..Delscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#Del().("Last-Modified") |
| 462 | c.RespHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#RespHeader..Headerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/WrappedHeader#Header..Delscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#Del().("Accept-Ranges") |
| 463 | |
| 464 | return false, caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.Errorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/Error().(statusCode, nil) |
| 465 | } |
| 466 | |
| 467 | // funcHumanize transforms size and time inputs to a human readable format. |
| 468 | // |
| 469 | // Size inputs are expected to be integers, and are formatted as a |
| 470 | // byte size, such as "83 MB". |
| 471 | // |
| 472 | // Time inputs are parsed using the given layout (default layout is RFC1123Z) |
| 473 | // and are formatted as a relative time, such as "2 weeks ago". |
| 474 | // See https://pkg.go.dev/time#pkg-constants for time layout docs. |
| 475 | func (c TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) funcHumanizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcHumanize().(formatType, data string) (string, error) { |
| 476 | // The format type can optionally be followed |
| 477 | // by a colon to provide arguments for the format |
| 478 | parts := stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Splitscip-go gomod github.com/golang/go/src go1.25.1 strings/Split().(formatType, ":") |
| 479 | |
| 480 | switch parts[0] { |
| 481 | case "size": |
| 482 | dataint, dataerr := strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/.ParseUintscip-go gomod github.com/golang/go/src go1.25.1 strconv/ParseUint().(data, 10, 64) |
| 483 | if dataerr != nil { |
| 484 | return "", fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("humanize: size cannot be parsed: %s", dataerr.Error()) |
| 485 | } |
| 486 | return humanizescip-go gomod github.com/dustin/go-humanize v1.0.1 `github.com/dustin/go-humanize`/.Bytesscip-go gomod github.com/dustin/go-humanize v1.0.1 `github.com/dustin/go-humanize`/Bytes().(dataint), nil |
| 487 | |
| 488 | case "time": |
| 489 | timelayout := timescip-go gomod github.com/golang/go/src go1.25.1 time/.RFC1123Zscip-go gomod github.com/golang/go/src go1.25.1 time/RFC1123Z. |
| 490 | if len(parts) > 1 { |
| 491 | timelayout = parts[1] |
| 492 | } |
| 493 | |
| 494 | dataint, dataerr := timescip-go gomod github.com/golang/go/src go1.25.1 time/.Parsescip-go gomod github.com/golang/go/src go1.25.1 time/Parse().(timelayout, data) |
| 495 | if dataerr != nil { |
| 496 | return "", fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("humanize: time cannot be parsed: %s", dataerr.Error()) |
| 497 | } |
| 498 | return humanizescip-go gomod github.com/dustin/go-humanize v1.0.1 `github.com/dustin/go-humanize`/.Timescip-go gomod github.com/dustin/go-humanize v1.0.1 `github.com/dustin/go-humanize`/Time().(dataint), nil |
| 499 | } |
| 500 | |
| 501 | return "", fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("no know function was given") |
| 502 | } |
| 503 | |
| 504 | // funcMaybe invokes the plugged-in function named functionName if it is plugged in |
| 505 | // (is a module in the 'http.handlers.templates.functions' namespace). If it is not |
| 506 | // available, a log message is emitted. |
| 507 | // |
| 508 | // The first argument is the function name, and the rest of the arguments are |
| 509 | // passed on to the actual function. |
| 510 | // |
| 511 | // This function is useful for executing templates that use components that may be |
| 512 | // considered as optional in some cases (like during local development) where you do |
| 513 | // not want to require everyone to have a custom Caddy build to be able to execute |
| 514 | // your template. |
| 515 | // |
| 516 | // NOTE: This function is EXPERIMENTAL and subject to change or removal. |
| 517 | func (c TemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#) funcMaybescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#funcMaybe().(functionName string, args ...any) (any, error) { |
| 518 | for _, funcMap := range c.CustomFuncsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#CustomFuncs. { |
| 519 | if fn, ok := funcMap[functionName]; ok { |
| 520 | val := reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.25.1 reflect/ValueOf().(fn) |
| 521 | if val.Kindscip-go gomod github.com/golang/go/src go1.25.1 reflect/Value#Kind().() != reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/.Funcscip-go gomod github.com/golang/go/src go1.25.1 reflect/Func. { |
| 522 | continue |
| 523 | } |
| 524 | argVals := make([]reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25.1 reflect/Value#, len(args)) |
| 525 | for i, arg := range args { |
| 526 | argVals[i] = reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.25.1 reflect/ValueOf().(arg) |
| 527 | } |
| 528 | returnVals := val.Callscip-go gomod github.com/golang/go/src go1.25.1 reflect/Value#Call().(argVals) |
| 529 | switch len(returnVals) { |
| 530 | case 0: |
| 531 | return "", nil |
| 532 | case 1: |
| 533 | return returnVals[0].Interfacescip-go gomod github.com/golang/go/src go1.25.1 reflect/Value#Interface().(), nil |
| 534 | case 2: |
| 535 | var err error |
| 536 | if !returnVals[1].IsNilscip-go gomod github.com/golang/go/src go1.25.1 reflect/Value#IsNil().() { |
| 537 | err = returnVals[1].Interfacescip-go gomod github.com/golang/go/src go1.25.1 reflect/Value#Interface().().(error) |
| 538 | } |
| 539 | return returnVals[0].Interfacescip-go gomod github.com/golang/go/src go1.25.1 reflect/Value#Interface().(), err |
| 540 | default: |
| 541 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("maybe %s: invalid number of return values: %d", functionName, len(returnVals)) |
| 542 | } |
| 543 | } |
| 544 | } |
| 545 | c.configscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/TemplateContext#config..loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/Templates#logger..Namedscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Named().("maybe").Warnscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Warn().("template function could not be found; ignoring invocation", zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Stringscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/String().("name", functionName)) |
| 546 | return "", nil |
| 547 | } |
| 548 | |
| 549 | // WrappedHeader wraps niladic functions so that they |
| 550 | // can be used in templates. (Template functions must |
| 551 | // return a value.) |
| 552 | type WrappedHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/WrappedHeader# struct{ httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Headerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/WrappedHeader#Header. } |
| 553 | |
| 554 | // Add adds a header field value, appending val to |
| 555 | // existing values for that field. It returns an |
| 556 | // empty string. |
| 557 | func (h WrappedHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/WrappedHeader#) Addscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/WrappedHeader#Add().(field, val string) string { |
| 558 | h.Headerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/WrappedHeader#Header..Addscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#Add().(field, val) |
| 559 | return "" |
| 560 | } |
| 561 | |
| 562 | // Set sets a header field value, overwriting any |
| 563 | // other values for that field. It returns an |
| 564 | // empty string. |
| 565 | func (h WrappedHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/WrappedHeader#) Setscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/WrappedHeader#Set().(field, val string) string { |
| 566 | h.Headerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/WrappedHeader#Header..Setscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#Set().(field, val) |
| 567 | return "" |
| 568 | } |
| 569 | |
| 570 | // Del deletes a header field. It returns an empty string. |
| 571 | func (h WrappedHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/WrappedHeader#) Delscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/WrappedHeader#Del().(field string) string { |
| 572 | h.Headerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/WrappedHeader#Header..Delscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#Del().(field) |
| 573 | return "" |
| 574 | } |
| 575 | |
| 576 | var bufPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/bufPool. = syncscip-go gomod github.com/golang/go/src go1.25.1 sync/.Poolscip-go gomod github.com/golang/go/src go1.25.1 sync/Pool#{ |
| 577 | Newscip-go gomod github.com/golang/go/src go1.25.1 sync/Pool#New.: func() any { |
| 578 | return new(bytesscip-go gomod github.com/golang/go/src go1.25.1 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.25.1 bytes/Buffer#) |
| 579 | }, |
| 580 | } |
| 581 | |
| 582 | // at time of writing, sprig.FuncMap() makes a copy, thus |
| 583 | // involves iterating the whole map, so do it just once |
| 584 | var sprigFuncMapscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/sprigFuncMap. = sprigscip-go gomod github.com/Masterminds/sprig/v3 v3.3.0 `github.com/Masterminds/sprig/v3`/.TxtFuncMapscip-go gomod github.com/Masterminds/sprig/v3 v3.3.0 `github.com/Masterminds/sprig/v3`/TxtFuncMap().() |
| 585 | |
| 586 | const recursionPreventionHeaderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/templates`/recursionPreventionHeader. = "Caddy-Templates-Include" |