HTMX with Go Development Guidelines
A set of best practices and instructions for integrating HTMX with Go, focusing on efficient and secure development:
HTMX and Go Best Practices
- Use Go’s
html/templatefor server-side rendering andhttp.HandlerFuncfor handling HTMX requests. - Utilize
gorilla/muxfor routing if needed andencoding/jsonfor JSON responses. - Implement proper error handling and logging, and use context for request cancellation and timeouts.
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 semantic HTML5 elements with HTMX attributes.
- Implement proper CSRF protection.
- Utilize HTMX extensions when necessary and
hx-boostfor full page navigation. - Follow Go’s idiomatic error handling and implement graceful server shutdown.
- Use Go modules for dependency management.
Overview of .cursorrules prompt
This prompt provides guidelines for integrating HTMX with Go, focusing on best practices for dynamic web development. It emphasizes using Go’s templating and routing capabilities alongside HTMX’s interactive features, while ensuring proper error handling, security, and dependency management. By following these guidelines, developers can build responsive web applications that leverage the strengths of both HTMX and Go, maintaining efficiency and security.
