aboutsummaryrefslogtreecommitdiff
path: root/http_template.go
blob: c1f5fc4aaa93e25cecab4748a525e1d7d24bd5c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

// SPDX-License-Identifier: AGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>

package main

import (
	"net/http"

	"go.lindenii.runxiyu.org/lindenii-common/clog"
)

// renderTemplate abstracts out the annoyances of reporting template rendering
// errors.
func renderTemplate(w http.ResponseWriter, templateName string, params map[string]any) {
	if err := templates.ExecuteTemplate(w, templateName, params); err != nil {
		http.Error(w, "error rendering template: "+err.Error(), http.StatusInternalServerError)
		clog.Error(err.Error())
	}
}