Use embedded filesystems properly.
This commit is contained in:
parent
27eb2e5f12
commit
c0bc02fed5
27
CLAUDE.md
27
CLAUDE.md
@ -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
|
@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/fs"
|
||||
"log/slog"
|
||||
"net"
|
||||
"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
|
||||
}
|
||||
|
||||
// Serve the templates and static files using embedded content
|
||||
// Serve templates from the embedded "templates" directory
|
||||
httpRequestRouter.Handle("/", http.FileServer(http.FS(embeds.Templates)))
|
||||
// Serve static files from the embedded "static" directory
|
||||
httpRequestRouter.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(embeds.Static))))
|
||||
// For embedded templates
|
||||
templateSubFS, err := fs.Sub(embeds.Templates, "templates")
|
||||
if err != nil {
|
||||
cfg.Logger.Error("Failed to create sub filesystem for templates", slog.Any("error", err))
|
||||
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
|
||||
cfg.Logger.Info("starting server",
|
||||
|
Loading…
x
Reference in New Issue
Block a user