HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //lib/go-1.22/src/internal/lazytemplate/lazytemplate.go
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package lazytemplate is a thin wrapper over text/template, allowing the use
// of global template variables without forcing them to be parsed at init.
package lazytemplate

import (
	"io"
	"os"
	"strings"
	"sync"
	"text/template"
)

// Template is a wrapper around text/template.Template, where the underlying
// template will be parsed the first time it is needed.
type Template struct {
	name, text string

	once sync.Once
	tmpl *template.Template
}

func (r *Template) tp() *template.Template {
	r.once.Do(r.build)
	return r.tmpl
}

func (r *Template) build() {
	r.tmpl = template.Must(template.New(r.name).Parse(r.text))
	r.name, r.text = "", ""
}

func (r *Template) Execute(w io.Writer, data any) error {
	return r.tp().Execute(w, data)
}

var inTest = len(os.Args) > 0 && strings.HasSuffix(strings.TrimSuffix(os.Args[0], ".exe"), ".test")

// New creates a new lazy template, delaying the parsing work until it is first
// needed. If the code is being run as part of tests, the template parsing will
// happen immediately.
func New(name, text string) *Template {
	lt := &Template{name: name, text: text}
	if inTest {
		// In tests, always parse the templates early.
		lt.tp()
	}
	return lt
}