Commit Graph

2 Commits

Author SHA1 Message Date
56c6045e3b Use ngx_log_error! macro and fix formatting
- Switched from ngx_log_error_core() to ngx_log_error! macro
- Changed error_log level from debug to info (cleaner output)
- Formatting cleanup across all modules (cargo fmt)
- Removed trailing newlines and fixed indentation

Logging now properly uses nginx's macro system for better
integration with nginx's log handling.
2025-11-15 17:16:55 -08:00
da38aba509 Refactor code into separate modules with clear boundaries
Code Organization:
- src/config.rs (133 lines): Configuration structs and merge implementations
- src/query.rs (327 lines): SQL query execution with parameter binding
- src/template.rs (160 lines): Template loading and management
- src/variable.rs (107 lines): Nginx variable resolution utilities
- src/lib.rs (387 lines): Module registration and directive handlers

Benefits:
✓ Single responsibility per module
✓ Better testability (tests co-located with code)
✓ Clearer separation of concerns
✓ Easier maintenance and debugging
✓ Reduced cognitive load (smaller files)

Module Breakdown:

config.rs:
- ModuleConfig (location-level config)
- MainConfig (HTTP-level config)
- Merge trait implementations
- 5 configuration tests

query.rs:
- execute_query() with named/positional parameter support
- Row-to-JSON conversion logic
- 7 query execution tests (data types, params, LIKE, etc.)

template.rs:
- load_templates_from_dir() for auto-discovery
- Template registration and override handling
- 3 template system tests

variable.rs:
- resolve_variable() for nginx variable access
- resolve_nginx_variable() using ngx_http_get_variable FFI
- 3 parameter handling tests

lib.rs:
- Module trait implementations (HttpModule, HttpModuleLocationConf, HttpModuleMainConf)
- nginx module registration (ngx_modules! macro)
- Command array and directive handlers
- HTTP request handler (tightly coupled with Module)

Test Coverage: 20 tests across all modules
All tests passing. Module verified working in production.
2025-11-15 15:38:20 -08:00