DomainScoreCursor Rules
GitHub

1/23/2025

A comprehensive guide to setting up a Go project with HTMX, including best practices, folder structure, and additional instructions for efficient development.



# Go (Basic Setup)

# Go with HTMX: Basic Setup and Best Practices

## Introduction
This guide provides a basic setup for integrating HTMX with Go, along with best practices to ensure efficient and maintainable code.

## Best Practices

```go
const htmxGoBestPractices = [
  "Use html/template for server-side rendering",
  "Implement http.HandlerFunc for handling HTMX requests",
  "Utilize gorilla/mux for routing if needed",
  "Use encoding/json for JSON responses",
  "Implement proper error handling and logging",
  "Utilize context for request cancellation and timeouts",
];
```

## Folder Structure

```go
const folderStructure = `
cmd/
  main.go
internal/
  handlers/
  models/
  templates/
static/
  css/
  js/
go.mod
go.sum
`;
```

## Additional Instructions

```go
const additionalInstructions = `
1. Use semantic HTML5 elements with HTMX attributes
2. Implement proper CSRF protection
3. Utilize HTMX extensions when needed
4. Use hx-boost for full page navigation
5. Follow Go's idiomatic error handling
6. Implement graceful shutdown for the server
7. Use Go modules for dependency management
`;
```

## Conclusion
By following these guidelines, you can set up a robust Go project with HTMX, ensuring best practices are adhered to for a maintainable and efficient codebase.