Add logging and fix /agents/ route error
All checks were successful
Build and Release / build (push) Successful in 35s

This commit is contained in:
Ducky SSH User
2025-12-20 07:34:02 +00:00
parent 761b91b031
commit 50dcfcdc83
9 changed files with 158 additions and 65 deletions

View File

@@ -1,42 +1,20 @@
# Nerd Monitor - Agent Guidelines
## Build & Test Commands
- **Generate templates**: `make templ`
- **Build**: `make build` (server + agent) or `make build-server`/`make build-agent`
- **Cross-platform**: `make build-all`
- **Clean**: `make clean`
- **Test all**: `go test ./...`
- **Test single**: `go test -run TestName ./package`
- **Format**: `gofmt -w ./cmd ./internal ./views`
```bash
# Generate Templ templates (required before building)
make templ
# Build server and agent for current OS
make build
# Build individual components
make build-server
make build-agent
# Build for all platforms (Linux, macOS, Windows)
make build-all
# Clean build artifacts
make clean
```
Note: This Go 1.21 project uses Templ for templating. Always run `make templ` before building.
Note: Go 1.23+ project using Templ templating. Run `make templ` before building.
## Code Style Guidelines
**Imports**: Standard library first, then third-party packages, then internal modules. Organize alphabetically within each group.
**Formatting & Types**: Use `gofmt` standards. Explicit struct field comments for exported types. Prefer `error` return values (no panic for recoverable errors).
**Naming**: CamelCase for exported symbols, lowercase for unexported. Receiver names as single letters (e.g., `(m *Manager)`). Constants use ALL_CAPS_SNAKE_CASE.
**Error Handling**: Define sentinel errors in dedicated files (e.g., `auth/errors.go`). Check errors explicitly; use `http.Error(w, "message", status)` for HTTP responses. Wrap errors with context when needed.
**Project Structure**:
- `cmd/`: Executable entry points (server, agent)
- `internal/`: Packages (api, auth, stats, store, ui)
- `views/`: Templ templates (*.templ files)
**Concurrency**: Use `sync.RWMutex` for shared state. Always defer lock releases. Keep critical sections small.
**HTTP**: Use Chi router. Handlers follow `func (h *Handler) Name(w http.ResponseWriter, r *http.Request)`. Set Content-Type headers explicitly. Validate query parameters early and return 400/404 appropriately.
- **Imports**: stdlib → third-party → internal (alphabetical within groups)
- **Formatting**: `gofmt` standards, explicit exported struct comments
- **Naming**: CamelCase exports, lowercase unexported, single-letter receivers (e.g., `(h *Handler)`)
- **Error Handling**: Explicit checks, `http.Error()` for HTTP, contextual wrapping
- **Concurrency**: `sync.RWMutex` for shared state, defer lock releases, small critical sections
- **HTTP**: Chi router, `func (h *Handler) Method(w http.ResponseWriter, r *http.Request)`, set Content-Type, validate early