HTMX with Go and Fiber Development Guidelines
A set of best practices and instructions for integrating HTMX with Go and Fiber, focusing on efficient and secure development:
HTMX, Go, and Fiber Best Practices
- Use Fiber’s HTML rendering for server-side templates and its routing system for HTMX requests.
- Utilize Fiber’s middleware for request processing and JSON methods for API responses.
- Implement proper error handling with Fiber’s error handling and use its static file serving for assets.
Folder Structure
Organize code into a structured directory:
textcmd/
main.go
internal/
handlers/
models/
templates/
static/
css/
js/
go.mod
go.sum
Additional Instructions
- Use Fiber’s
App.Get/Post/etc
for routing HTMX requests. - Implement CSRF protection using Fiber middleware.
- Utilize Fiber’s Context for handling HTMX-specific headers and its template engine for server-side rendering.
- Implement proper logging with Fiber’s Logger middleware and follow Fiber’s best practices for project structure.
- Use environment variables for configuration.
Overview of .cursorrules prompt
his prompt provides guidelines for integrating HTMX with Go and the Fiber framework, focusing on best practices for dynamic web development. It emphasizes using Fiber’s templating, routing, and middleware capabilities to enhance HTMX’s interactive features, while ensuring proper error handling, security, and logging. By following these guidelines, developers can build responsive web applications that leverage the strengths of HTMX, Go, and Fiber, maintaining efficiency and security.