Skip to content

Commit d3e609b

Browse files
committed
feat: embed error.html template and move loading to main
- Bundle error.html template using go:embed for self-contained binaries - Move template loading from init() to main() after logging setup - Remove template file copy from Dockerfile since templates are embedded - Add proper error template initialization with structured logging - Support ko builds with no external file dependencies - Remove template copy from Dockerfile 🤖 Generated with GitHub Copilot (via Zed) Signed-off-by: Eric Searcy <eric@linuxfoundation.org>
1 parent 769e4f7 commit d3e609b

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,5 @@ USER nonroot
3333
EXPOSE 8080
3434

3535
COPY --from=builder /go/bin/auth0-cas-server-go /auth0-cas-server-go
36-
COPY --from=builder /build/templates /templates
3736

3837
ENTRYPOINT ["/auth0-cas-server-go", "-p=8080"]

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func main() {
8484
logger := slog.New(handler)
8585
slog.SetDefault(logger)
8686

87+
// Initialize error template after logging is set up.
88+
initErrorTemplate()
89+
8790
// Instrument Open Telemetry.
8891
if !*noTrace {
8992
// Start OTLP forwarder and register the global tracing provider.

responses.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package main
77
// spell-checker:disable
88
import (
99
"context"
10+
_ "embed"
1011
"encoding/json"
1112
"encoding/xml"
1213
"errors"
@@ -80,6 +81,8 @@ var (
8081

8182
// spell-checker:enable
8283

84+
//go:embed templates/error.html
85+
errorTemplateContent string
8386
// errorTemplate is the HTML template for error pages.
8487
errorTemplate *template.Template
8588
)
@@ -91,10 +94,11 @@ type ErrorPageData struct {
9194
ShowBackButton bool
9295
}
9396

94-
// init initializes the error page template.
95-
func init() {
97+
// initErrorTemplate initializes the error page template from embedded content.
98+
// This should be called from main() after logging is set up.
99+
func initErrorTemplate() {
96100
var err error
97-
errorTemplate, err = template.ParseFiles("templates/error.html")
101+
errorTemplate, err = template.New("error.html").Parse(errorTemplateContent)
98102
if err != nil {
99103
// Log error but don't fail - we'll fall back to plain text errors.
100104
// This allows the service to start even if templates are missing.

0 commit comments

Comments
 (0)