fix embeding issue and sqlite db new database string

This commit is contained in:
ghostersk
2026-03-08 06:51:04 +00:00
parent 97e07689a9
commit 964a345657
4 changed files with 15 additions and 11 deletions

View File

@@ -31,6 +31,8 @@ A self-hosted, encrypted web email client written entirely in Go. Supports Gmail
# 1. Clone / copy the project
git clone https://github.com/ghostersk/gowebmail && cd gowebmail
go build -o gowebmail ./cmd/server
# if you want smaller exe ( strip down debuginformation):
go build -ldflags="-s -w" -o gowebmail ./cmd/server
./gowebmail
```

View File

@@ -27,7 +27,8 @@ func New(path string, encKey []byte) (*DB, error) {
}
// Enable WAL mode and foreign keys for performance and integrity
dsn := fmt.Sprintf("%s?_journal_mode=WAL&_foreign_keys=on&_busy_timeout=5000", path)
// sqlite file path must start with `file:` for package mattn/go-sqlite3
dsn := fmt.Sprintf("file:%s?_journal_mode=WAL&_foreign_keys=on&_busy_timeout=5000", path)
sqlDB, err := sql.Open("sqlite3", dsn)
if err != nil {
return nil, fmt.Errorf("open sqlite: %w", err)

View File

@@ -4,9 +4,11 @@ import (
"bytes"
"fmt"
"html/template"
"io/fs"
"log"
"net/http"
"path/filepath"
"github.com/ghostersk/gowebmail"
)
// Renderer holds one compiled *template.Template per page name.
@@ -16,11 +18,6 @@ type Renderer struct {
templates map[string]*template.Template
}
const (
tmplBase = "web/templates/base.html"
tmplDir = "web/templates"
)
// NewRenderer parses every page template paired with the base layout.
// Call once at startup; fails fast if any template has a syntax error.
func NewRenderer() (*Renderer, error) {
@@ -30,19 +27,23 @@ func NewRenderer() (*Renderer, error) {
"mfa.html",
"admin.html",
}
templateFS, err := fs.Sub(gowebmail.WebFS, "web/templates")
if err != nil {
log.Fatalf("embed templates fs: %v", err)
}
r := &Renderer{templates: make(map[string]*template.Template, len(pages))}
for _, page := range pages {
pagePath := filepath.Join(tmplDir, page)
// New instance per page — base FIRST, then the page file.
// This means the page's {{define}} blocks override the base's {{block}} defaults
// without any other page's definitions being present in the same pool.
t, err := template.New("base").ParseFiles(tmplBase, pagePath)
t, err := template.ParseFS(templateFS, "base.html", page)
if err != nil {
return nil, fmt.Errorf("renderer: parse %s: %w", page, err)
}
name := page[:len(page)-5] // strip ".html"
name := page[:len(page)-5]
r.templates[name] = t
log.Printf("renderer: loaded template %q", name)
}

View File

@@ -4,5 +4,5 @@ import "embed"
// Global access to the web assets
//
//go:embed web/static/** web/templates/**
//go:embed web/static/css/* web/static/js/* web/static/img/* web/templates/**
var WebFS embed.FS