Source File
template.go
Belonging Package
html/template
package template
import (
)
func ( *Template) () error {
.nameSpace.mu.Lock()
defer .nameSpace.mu.Unlock()
.nameSpace.escaped = true
if .escapeErr == nil {
if .Tree == nil {
return fmt.Errorf("template: %q is an incomplete or empty template", .Name())
}
if := escapeTemplate(, .text.Root, .Name()); != nil {
return
}
} else if .escapeErr != escapeOK {
return .escapeErr
}
return nil
}
func ( *Template) ( string) ( *Template, error) {
.nameSpace.mu.Lock()
defer .nameSpace.mu.Unlock()
.nameSpace.escaped = true
= .set[]
if == nil {
return nil, fmt.Errorf("html/template: %q is undefined", )
}
if .escapeErr != nil && .escapeErr != escapeOK {
return nil, .escapeErr
}
if .text.Tree == nil || .text.Root == nil {
return nil, fmt.Errorf("html/template: %q is an incomplete template", )
}
if .text.Lookup() == nil {
panic("html/template internal error: template escaping out of sync")
}
if .escapeErr == nil {
= escapeTemplate(, .text.Root, )
}
return ,
}
func ( *Template) () string {
return .text.DefinedTemplates()
}
func ( *Template) () (*Template, error) {
.nameSpace.mu.Lock()
defer .nameSpace.mu.Unlock()
if .escapeErr != nil {
return nil, fmt.Errorf("html/template: cannot Clone %q after it has executed", .Name())
}
, := .text.Clone()
if != nil {
return nil,
}
:= &nameSpace{set: make(map[string]*Template)}
.esc = makeEscaper()
:= &Template{
nil,
,
.Tree,
,
}
.set[.Name()] =
for , := range .Templates() {
:= .Name()
:= .set[]
if == nil || .escapeErr != nil {
return nil, fmt.Errorf("html/template: cannot Clone %q after it has executed", .Name())
}
.Tree = .Tree.Copy()
.set[] = &Template{
nil,
,
.Tree,
.nameSpace,
}
func ( ...string) (*Template, error) {
return parseFiles(nil, readFileOS, ...)
}
func ( *Template) ( ...string) (*Template, error) {
return parseFiles(, readFileOS, ...)
}
func ( *Template) ( fs.FS, ...string) (*Template, error) {
return parseFS(, , )
}
func ( *Template, fs.FS, []string) (*Template, error) {
var []string
for , := range {
, := fs.Glob(, )
if != nil {
return nil,
}
if len() == 0 {
return nil, fmt.Errorf("template: pattern matches no files: %#q", )
}
= append(, ...)
}
return parseFiles(, readFileFS(), ...)
}
func ( string) ( string, []byte, error) {
= filepath.Base()
, = os.ReadFile()
return
}
func ( fs.FS) func(string) (string, []byte, error) {
return func( string) ( string, []byte, error) {
= path.Base()
, = fs.ReadFile(, )
return
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |