Use embedded filesystems properly.

This commit is contained in:
Christian Galo 2025-05-13 22:49:36 -05:00
parent 27eb2e5f12
commit c0bc02fed5
2 changed files with 11 additions and 32 deletions

View File

@ -1,27 +0,0 @@
# CLAUDE.md - Member Console Guidelines
## Build & Run Commands
- Build: `go build -o member-console`
- Run: `go run main.go start`
- Run with config: `go run main.go start --config path/to/config.yaml`
- Test: `go test ./...`
- Test specific: `go test ./internal/auth`
- Lint: `golangci-lint run`
## Code Style Guidelines
- **Formatting**: Standard Go formatting with `gofmt`
- **Imports**: Group by standard lib, then external, then internal
- **Naming**:
- Packages: lowercase, single word
- Exported functions: PascalCase
- Internal functions: camelCase
- Variables: camelCase
- **Error Handling**: Check errors with `if err != nil`, use descriptive messages
- **Security**: Implement secure headers, CSRF protection, proper session management
- **Documentation**: Comment all exported functions and types
- **Configuration**: Use Viper with env vars (WCMC prefix)
## Architecture
- Clean separation of concerns (middleware, auth, handlers)
- Follow Go project layout standards
- Protected routes should implement CSRF protection

View File

@ -2,6 +2,7 @@ package server
import ( import (
"context" "context"
"io/fs"
"log/slog" "log/slog"
"net" "net"
"net/http" "net/http"
@ -87,11 +88,16 @@ func Start(ctx context.Context, cfg Config) error {
BaseContext: func(_ net.Listener) context.Context { return ctx }, // Pass base context to all requests BaseContext: func(_ net.Listener) context.Context { return ctx }, // Pass base context to all requests
} }
// Serve the templates and static files using embedded content // For embedded templates
// Serve templates from the embedded "templates" directory templateSubFS, err := fs.Sub(embeds.Templates, "templates")
httpRequestRouter.Handle("/", http.FileServer(http.FS(embeds.Templates))) if err != nil {
// Serve static files from the embedded "static" directory cfg.Logger.Error("Failed to create sub filesystem for templates", slog.Any("error", err))
httpRequestRouter.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(embeds.Static)))) return err
}
httpRequestRouter.Handle("/", http.FileServer(http.FS(templateSubFS)))
// For embedded static files
httpRequestRouter.Handle("/static/", http.FileServer(http.FS(embeds.Static)))
// Log server startup with structured logging // Log server startup with structured logging
cfg.Logger.Info("starting server", cfg.Logger.Info("starting server",