mirror of
https://github.com/btouchard/ackify.git
synced 2026-01-07 05:19:43 -06:00
feat: migrate templates from embedded filesystem to file-based system
- Move templates from webtemplates/templates/ to templates/ - Replace embedded filesystem with filesystem-based template loading - Add ACKIFY_TEMPLATES_DIR environment variable for custom template paths - Update Dockerfile to copy templates and set default template directory - Improve template resolution with fallback paths for development - Remove webtemplates package and embedded filesystem dependencies - Update BUILD.md documentation for template configuration
This commit is contained in:
@@ -37,4 +37,7 @@ OAUTH_COOKIE_SECRET=your_base64_encoded_secret_key
|
||||
ED25519_PRIVATE_KEY_B64=your_base64_encoded_ed25519_private_key
|
||||
|
||||
# Server Configuration
|
||||
LISTEN_ADDR=:8080
|
||||
LISTEN_ADDR=:8080
|
||||
|
||||
# Template Configuration
|
||||
# ACKIFY_TEMPLATES_DIR=/custom/path/to/templates
|
||||
3
BUILD.md
3
BUILD.md
@@ -57,6 +57,9 @@ Required environment variables:
|
||||
- `DB_DSN`: PostgreSQL connection string
|
||||
- `OAUTH_COOKIE_SECRET`: Base64-encoded secret for session cookies
|
||||
|
||||
Optional template configuration:
|
||||
- `ACKIFY_TEMPLATES_DIR`: Custom path to HTML templates directory (defaults to relative path for development, `/app/templates` in Docker)
|
||||
|
||||
### OAuth2 Providers
|
||||
|
||||
Supported providers:
|
||||
|
||||
@@ -60,10 +60,15 @@ COPY --from=builder /app/ackify /app/ackify
|
||||
COPY --from=builder /app/migrate /app/migrate
|
||||
COPY --from=builder /app/migrations /app/migrations
|
||||
|
||||
# Copy templates for filesystem loading
|
||||
COPY --from=builder /app/templates /app/templates
|
||||
|
||||
# Set default environment variable for templates directory
|
||||
ENV ACKIFY_TEMPLATES_DIR=/app/templates
|
||||
|
||||
# Use non-root user (already set in distroless image)
|
||||
# USER 65532:65532
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
|
||||
ENTRYPOINT ["/app/ackify"]
|
||||
|
||||
68
go.sum
68
go.sum
@@ -1,24 +1,92 @@
|
||||
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
|
||||
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
|
||||
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
|
||||
github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI=
|
||||
github.com/containerd/errdefs v1.0.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M=
|
||||
github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE=
|
||||
github.com/containerd/errdefs/pkg v0.3.0/go.mod h1:NJw6s9HwNuRhnjJhM7pylWwMyAkmCQvQ4GpJHEqRLVk=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dhui/dktest v0.4.6 h1:+DPKyScKSEp3VLtbMDHcUq6V5Lm5zfZZVb0Sk7Ahom4=
|
||||
github.com/dhui/dktest v0.4.6/go.mod h1:JHTSYDtKkvFNFHJKqCzVzqXecyv+tKt8EzceOmQOgbU=
|
||||
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
|
||||
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
|
||||
github.com/docker/docker v28.3.3+incompatible h1:Dypm25kh4rmk49v1eiVbsAtpAsYURjYkaKubwuBdxEI=
|
||||
github.com/docker/docker v28.3.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
||||
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
|
||||
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
|
||||
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
|
||||
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
|
||||
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||
github.com/go-chi/chi/v5 v5.2.3 h1:WQIt9uxdsAbgIYgid+BpYc+liqQZGMHRaUwp0JUcvdE=
|
||||
github.com/go-chi/chi/v5 v5.2.3/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
|
||||
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
github.com/golang-migrate/migrate/v4 v4.19.0 h1:RcjOnCGz3Or6HQYEJ/EEVLfWnmw9KnoigPSjzhCuaSE=
|
||||
github.com/golang-migrate/migrate/v4 v4.19.0/go.mod h1:9dyEcu+hO+G9hPSw8AIg50yg622pXJsoHItQnDGZkI0=
|
||||
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
|
||||
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
|
||||
github.com/gorilla/sessions v1.4.0 h1:kpIYOp/oi6MG/p5PgxApU8srsSw9tuFbt46Lt7auzqQ=
|
||||
github.com/gorilla/sessions v1.4.0/go.mod h1:FLWm50oby91+hl7p/wRxDth9bWSuk0qVL2emc7lT5ik=
|
||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
|
||||
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
|
||||
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
|
||||
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
|
||||
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
|
||||
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
|
||||
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
|
||||
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
|
||||
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
|
||||
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
|
||||
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
|
||||
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
|
||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 h1:TT4fX+nBOA/+LUkobKGW1ydGcn+G3vRw9+g5HwCphpk=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0/go.mod h1:L7UH0GbB0p47T4Rri3uHjbpCFYrVrwc1I25QhNPiGK8=
|
||||
go.opentelemetry.io/otel v1.37.0 h1:9zhNfelUvx0KBfu/gb+ZgeAfAgtWrfHJZcAqFC228wQ=
|
||||
go.opentelemetry.io/otel v1.37.0/go.mod h1:ehE/umFRLnuLa/vSccNq9oS1ErUlkkK71gMcN34UG8I=
|
||||
go.opentelemetry.io/otel/metric v1.37.0 h1:mvwbQS5m0tbmqML4NqK+e3aDiO02vsf/WgbsdpcPoZE=
|
||||
go.opentelemetry.io/otel/metric v1.37.0/go.mod h1:04wGrZurHYKOc+RKeye86GwKiTb9FKm1WHtO+4EVr2E=
|
||||
go.opentelemetry.io/otel/trace v1.37.0 h1:HLdcFNbRQBE2imdSEgm/kwqmQj1Or1l/7bW6mxVK7z4=
|
||||
go.opentelemetry.io/otel/trace v1.37.0/go.mod h1:TlgrlQ+PtQO5XFerSPUYG0JSgGyryXewPGyayAWSBS0=
|
||||
golang.org/x/oauth2 v0.31.0 h1:8Fq0yVZLh4j4YA47vHKFTa9Ew5XIrCP8LC6UeNZnLxo=
|
||||
golang.org/x/oauth2 v0.31.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
|
||||
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
||||
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
|
||||
@@ -15,7 +17,6 @@ import (
|
||||
"github.com/btouchard/ackify-ce/internal/infrastructure/database"
|
||||
"github.com/btouchard/ackify-ce/internal/presentation/handlers"
|
||||
"github.com/btouchard/ackify-ce/pkg/crypto"
|
||||
"github.com/btouchard/ackify-ce/webtemplates"
|
||||
)
|
||||
|
||||
// Server represents the Ackify CE web server
|
||||
@@ -123,7 +124,7 @@ func initInfrastructure(ctx context.Context) (*config.Config, *sql.DB, *template
|
||||
}
|
||||
|
||||
// Initialize templates
|
||||
tmpl, err := webtemplates.InitTemplates()
|
||||
tmpl, err := initTemplates()
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, fmt.Errorf("failed to initialize templates: %w", err)
|
||||
}
|
||||
@@ -168,3 +169,59 @@ func setupRouter(
|
||||
|
||||
return router
|
||||
}
|
||||
|
||||
// initTemplates initializes HTML templates from filesystem
|
||||
func initTemplates() (*template.Template, error) {
|
||||
templatesDir := getTemplatesDir()
|
||||
|
||||
// Parse the base template first
|
||||
baseTemplatePath := filepath.Join(templatesDir, "base.html.tpl")
|
||||
tmpl, err := template.New("base").ParseFiles(baseTemplatePath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse base template: %w", err)
|
||||
}
|
||||
|
||||
// Parse the additional templates
|
||||
additionalTemplates := []string{"index.html.tpl", "sign.html.tpl", "signatures.html.tpl", "embed.html.tpl"}
|
||||
for _, templateFile := range additionalTemplates {
|
||||
templatePath := filepath.Join(templatesDir, templateFile)
|
||||
_, err = tmpl.ParseFiles(templatePath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse template %s: %w", templateFile, err)
|
||||
}
|
||||
}
|
||||
|
||||
return tmpl, nil
|
||||
}
|
||||
|
||||
// getTemplatesDir resolves the templates directory path
|
||||
func getTemplatesDir() string {
|
||||
// Check environment variable
|
||||
if envDir := os.Getenv("ACKIFY_TEMPLATES_DIR"); envDir != "" {
|
||||
return envDir
|
||||
}
|
||||
|
||||
// Default behavior: try to resolve from executable location
|
||||
if execPath, err := os.Executable(); err == nil {
|
||||
execDir := filepath.Dir(execPath)
|
||||
defaultDir := filepath.Join(execDir, "templates")
|
||||
if _, err := os.Stat(defaultDir); err == nil {
|
||||
return defaultDir
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback for development: check multiple possible paths
|
||||
possiblePaths := []string{
|
||||
"templates", // When running from project root
|
||||
"./templates", // Alternative relative path
|
||||
}
|
||||
|
||||
for _, path := range possiblePaths {
|
||||
if _, err := os.Stat(path); err == nil {
|
||||
return path
|
||||
}
|
||||
}
|
||||
|
||||
// Final fallback - let the error happen in template loading
|
||||
return "templates"
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Service de validation de lecture</title>
|
||||
<title>Ackify - Proof of Read</title>
|
||||
{{if .DocID}}
|
||||
<link rel="alternate" type="application/json+oembed" href="/oembed?url={{.BaseURL}}/sign?doc={{.DocID}}&format=json" title="Signataires du document {{.DocID}}" />
|
||||
{{end}}
|
||||
@@ -34,7 +34,7 @@
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
||||
</svg>
|
||||
</div>
|
||||
<h1 class="text-xl font-bold text-slate-900">Service de validation de lecture</h1>
|
||||
<h1 class="text-xl font-bold text-slate-900">Ackify - Proof of Read</h1>
|
||||
</div>
|
||||
{{if .User}}
|
||||
<div class="flex items-center space-x-4">
|
||||
@@ -1,30 +0,0 @@
|
||||
package webtemplates
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
)
|
||||
|
||||
//go:embed templates/*.tpl
|
||||
var TemplatesFS embed.FS
|
||||
|
||||
// InitTemplates initializes the HTML templates from embedded files
|
||||
func InitTemplates() (*template.Template, error) {
|
||||
// Parse the base template first
|
||||
tmpl, err := template.New("base").ParseFS(TemplatesFS, "templates/base.html.tpl")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse base template: %w", err)
|
||||
}
|
||||
|
||||
// Parse the additional templates
|
||||
additionalTemplates := []string{"templates/index.html.tpl", "templates/sign.html.tpl", "templates/signatures.html.tpl", "templates/embed.html.tpl"}
|
||||
for _, templateFile := range additionalTemplates {
|
||||
_, err = tmpl.ParseFS(TemplatesFS, templateFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse template %s: %w", templateFile, err)
|
||||
}
|
||||
}
|
||||
|
||||
return tmpl, nil
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package webtemplates
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTemplatesFS(t *testing.T) {
|
||||
// Test that the embedded filesystem contains the expected files
|
||||
expectedFiles := []string{
|
||||
"templates/base.html.tpl",
|
||||
"templates/index.html.tpl",
|
||||
"templates/sign.html.tpl",
|
||||
"templates/signatures.html.tpl",
|
||||
"templates/embed.html.tpl",
|
||||
}
|
||||
|
||||
for _, file := range expectedFiles {
|
||||
data, err := TemplatesFS.ReadFile(file)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to read embedded file %s: %v", file, err)
|
||||
}
|
||||
if len(data) == 0 {
|
||||
t.Errorf("Embedded file %s is empty", file)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInitTemplates(t *testing.T) {
|
||||
// Test that InitTemplates works correctly
|
||||
tmpl, err := InitTemplates()
|
||||
if err != nil {
|
||||
t.Fatalf("InitTemplates failed: %v", err)
|
||||
}
|
||||
|
||||
if tmpl == nil {
|
||||
t.Fatal("InitTemplates returned nil template")
|
||||
}
|
||||
|
||||
// Test that all expected templates are parsed
|
||||
expectedTemplateNames := []string{
|
||||
"base",
|
||||
"base.html.tpl",
|
||||
"index.html.tpl",
|
||||
"sign.html.tpl",
|
||||
"signatures.html.tpl",
|
||||
"embed.html.tpl",
|
||||
}
|
||||
|
||||
for _, name := range expectedTemplateNames {
|
||||
if tmpl.Lookup(name) == nil {
|
||||
t.Errorf("Template %s not found in parsed templates", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user