feat: Complete all remaining Future Improvements (#4-8)

Implemented 5 additional architectural improvements:

1. Response Types (types.go)
   - APIResponse with Success, Data, Error, Meta fields
   - ErrorInfo with Code, Message, Field, Details
   - MetaInfo with Timestamp, Version, RequestID
   - SuccessResponse() and NewErrorResponse() helpers
   - HealthCheckResponse for health endpoint
   - Consistent JSON API responses

2. Validation Tags (types.go)
   - Added struct tags to LanguageRequest
   - Added struct tags to PDFExportRequest
   - Declarative validation rules (oneof, required)
   - Self-documenting validation constraints
   - Ready for go-playground/validator integration

3. Context Helper Functions (middleware/preferences.go)
   - GetLanguage(), GetCVLength(), GetCVIcons(), GetCVTheme(), GetColorTheme()
   - IsLongCV(), IsShortCV() boolean helpers
   - ShowIcons(), HideIcons() boolean helpers
   - IsCleanTheme(), IsDefaultTheme() boolean helpers
   - IsDarkMode(), IsLightMode() boolean helpers
   - 13 new convenience functions for cleaner code

4. Typed Errors (errors.go)
   - ErrorCode constants for all error types
   - DomainError with Code, Message, Err, StatusCode, Field
   - Unwrap() support for error chains
   - WithError() and WithField() fluent builders
   - InvalidLanguageError(), InvalidLengthError(), etc.
   - PDFGenerationError(), MethodNotAllowedError(), RateLimitError()
   - 13 error codes, domain-specific constructors

5. Benchmark Tests
   - handlers/benchmarks_test.go (11 benchmarks)
   - middleware/benchmarks_test.go (12 benchmarks)
   - Sequential benchmarks for handlers, middleware, request parsing
   - Parallel benchmarks for concurrent load testing
   - Response creation benchmarks
   - Helper function benchmarks

Benefits:
- Type Safety: Validation tags and structured types
- Developer Experience: 13 context helpers reduce boilerplate
- Error Handling: Domain-specific errors with codes
- Performance Monitoring: 23 benchmarks for regression detection
- API Consistency: Standardized response formats
- Maintainability: Self-documenting validation and errors

Testing:
- All unit tests pass
- All benchmarks working
- Build succeeds
- No breaking changes
This commit is contained in:
juanatsap
2025-11-20 18:05:45 +00:00
parent ae89d84e07
commit 4528e04bad
10 changed files with 636 additions and 13 deletions
@@ -2,9 +2,9 @@
<!-- Download PDF Button (Fixed Left) -->
<button
id="download-button"
class="fixed-btn download-btn no-print"
class="fixed-btn download-btn no-print has-tooltip"
aria-label="{{if eq .Lang "es"}}Descargar PDF{{else}}Download PDF{{end}}"
title="{{if eq .Lang "es"}}Descargar PDF{{else}}Download PDF{{end}}"
data-tooltip="{{if eq .Lang "es"}}Descargar PDF{{else}}Download PDF{{end}}"
onclick="document.getElementById('pdf-modal').showModal()"
_="on mouseenter call syncPdfHover(true)
on mouseleave call syncPdfHover(false)">
@@ -2,9 +2,9 @@
<!-- Print-Friendly Button (Fixed Left) -->
<button
id="print-friendly-button"
class="fixed-btn print-friendly-btn no-print"
class="fixed-btn print-friendly-btn no-print has-tooltip"
aria-label="{{if eq .Lang "es"}}Imprimir CV{{else}}Print CV{{end}}"
title="{{if eq .Lang "es"}}Imprimir CV{{else}}Print CV{{end}}"
data-tooltip="{{if eq .Lang "es"}}Imprimir CV{{else}}Print CV{{end}}"
onclick="window.print()"
_="on mouseenter call syncPrintHover(true)
on mouseleave call syncPrintHover(false)">
@@ -2,10 +2,10 @@
<!-- Keyboard Shortcuts Button (Fixed Right) -->
<button
id="shortcuts-button"
class="fixed-btn shortcuts-btn no-print"
class="fixed-btn shortcuts-btn no-print has-tooltip tooltip-left"
onclick="document.getElementById('shortcuts-modal').showModal()"
aria-label="{{if eq .Lang "es"}}Atajos de teclado{{else}}Keyboard shortcuts{{end}}"
title="{{if eq .Lang "es"}}Atajos de teclado (?){{else}}Keyboard shortcuts (?){{end}}">
data-tooltip="{{if eq .Lang "es"}}Atajos de teclado (?){{else}}Keyboard shortcuts (?){{end}}">
<iconify-icon icon="mdi:keyboard-outline" width="28" height="28"></iconify-icon>
</button>
{{end}}
@@ -2,9 +2,9 @@
<!-- Zoom Toggle Button (Fixed Right, above shortcuts button) -->
<button
id="zoom-toggle-button"
class="fixed-btn zoom-toggle-btn no-print"
class="fixed-btn zoom-toggle-btn no-print has-tooltip tooltip-left"
aria-label="{{if eq .Lang "es"}}Alternar control de zoom{{else}}Toggle zoom control{{end}}"
title="{{if eq .Lang "es"}}Control de zoom{{else}}Zoom control{{end}}"
data-tooltip="{{if eq .Lang "es"}}Control de zoom{{else}}Zoom control{{end}}"
_="on mouseenter call highlightZoomControl(true)
on mouseleave call highlightZoomControl(false)">
<iconify-icon icon="mdi:magnify" width="28" height="28"></iconify-icon>