summaryrefslogtreecommitdiffstats
path: root/roseh.moe.go
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@google.com>2026-07-23 15:26:31 -0700
committerRose Hogenson <rhogenson@google.com>2026-07-23 15:27:24 -0700
commit8cfead0704354399baecaf3e279c730bed78b359 (patch)
treee2eb2bd9f7770d9acfe623b5c5cba28c681770d8 /roseh.moe.go
parente0ca1bde9435ade640a12ca93965e88866c3b856 (diff)
downloadroseh.moe-8cfead0704354399baecaf3e279c730bed78b359.tar.zst
Add a helper function for making an outlined template
Diffstat (limited to 'roseh.moe.go')
-rw-r--r--roseh.moe.go32
1 files changed, 23 insertions, 9 deletions
diff --git a/roseh.moe.go b/roseh.moe.go
index 20c2101..cef9657 100644
--- a/roseh.moe.go
+++ b/roseh.moe.go
@@ -146,6 +146,24 @@ func loadConfig() (*serviceConfiguration, error) {
}
var (
+ //go:embed templates/outline.html.template
+ outlineString string
+ outlineTemplate = template.Must(template.New("outline").Parse(outlineString))
+)
+
+func outlinedTemplate(s string) (*template.Template, error) {
+ outline, err := outlineTemplate.Clone()
+ if err != nil {
+ return nil, err
+ }
+ t, err := outline.New("body").Parse(s)
+ if err != nil {
+ return nil, err
+ }
+ return t.Lookup("outline"), nil
+}
+
+var (
//go:embed templates/404.html.template
notFoundString string
notFoundTemplate = template.Must(template.New("notFound").Parse(notFoundString))
@@ -162,13 +180,9 @@ func notFound(w http.ResponseWriter, r *http.Request) {
}
var (
- //go:embed templates/outline.html.template
- outlineString string
- outlineTemplate = template.Must(template.New("outline").Parse(outlineString))
-
//go:embed templates/index.html.template
indexString string
- indexTemplate = template.Must(template.Must(outlineTemplate.Clone()).New("body").Parse(indexString)).Lookup("outline")
+ indexTemplate = template.Must(outlinedTemplate(indexString))
)
func index(w http.ResponseWriter, _ *http.Request) {
@@ -233,7 +247,7 @@ func qrHandler(w http.ResponseWriter, r *http.Request) {
var (
//go:embed templates/wormhole.html.template
wormholeTemplateString string
- wormholeTemplate = template.Must(template.Must(outlineTemplate.Clone()).New("body").Parse(wormholeTemplateString)).Lookup("outline")
+ wormholeTemplate = template.Must(outlinedTemplate(wormholeTemplateString))
)
type wormholeTemplateArgs struct {
@@ -441,7 +455,7 @@ func uploadWormhole(reader *multipart.Reader) (string, error) {
var (
//go:embed templates/wormhole-success.html.template
wormholeSuccessTemplateString string
- wormholeSuccessTemplate = template.Must(template.Must(outlineTemplate.Clone()).New("body").Parse(wormholeSuccessTemplateString)).Lookup("outline")
+ wormholeSuccessTemplate = template.Must(outlinedTemplate(wormholeSuccessTemplateString))
)
type wormholeSuccessTemplateArgs struct {
@@ -680,7 +694,7 @@ func checkPassword(password, auth string) bool {
var (
//go:embed templates/login.html.template
loginTemplateString string
- loginTemplate = template.Must(template.Must(outlineTemplate.Clone()).New("body").Parse(loginTemplateString)).Lookup("outline")
+ loginTemplate = template.Must(outlinedTemplate(loginTemplateString))
)
type loginTemplateArgs struct {
@@ -732,7 +746,7 @@ func login(w http.ResponseWriter, r *http.Request) {
var (
//go:embed templates/note.html.template
notepadString string
- notepadTemplate = template.Must(template.Must(outlineTemplate.Clone()).New("body").Parse(notepadString)).Lookup("outline")
+ notepadTemplate = template.Must(outlinedTemplate(notepadString))
notepadContentsMu sync.Mutex
notepadContents string