Skip to content

refactor: v0.8.0 — graceful shutdown, performance improvements, and bug fixes - #22

Merged
kk0829 merged 6 commits into
mainfrom
refactor/improvements
Mar 29, 2026
Merged

kk0829 merged 6 commits into
mainfrom
refactor/improvements

Conversation

@kk0829

@kk0829 kk0829 commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR introduces a major refactoring of the Lightning framework, improving reliability, performance, and developer experience. Test coverage has been increased from 81.2% to 90.9%.

Changes

✨ New Features

  • Graceful Shutdown — Added Run(), RunListener(), Shutdown(), and RunGraceful() methods with automatic signal handling (SIGINT/SIGTERM)
  • Context Pool — Introduced sync.Pool for Context reuse, significantly reducing GC pressure
  • Request Body Size Limit — Added MaxRequestBodySize configuration option
  • Middleware Caching — Route groups now cache middleware for improved routing performance
  • Integration Tests — Added comprehensive integration tests with dynamic port allocation

⚠️ Breaking Changes

  • Debug mode default changed from true to false — set Config.Debug = true explicitly if needed

🐛 Bug Fixes

  • Fixed critical shutdown issue where the server wouldn't stop properly
  • Fixed nil pointer panic during config merge
  • Fixed request body size limit enforcement
  • Fixed Context pool reuse bug where data wasn't being reset properly
  • Fixed X-Forwarded-For header parsing to correctly handle comma-separated IP addresses

🔄 Other Improvements

  • Replaced interface{} with any throughout the codebase
  • Logger middleware now uses ctx.App.Logger.Info() instead of fmt.Printf
  • Improved global logger implementation
  • Removed deprecated and unused code

Test Results

Metric Before After
Test Coverage 81.2% 90.9%

Commits

  • 27e8f74 fix: resolve P1 performance and security issues
  • e74f830 fix: resolve P2 design and functionality issues
  • bcb6b97 fix: resolve P3 code quality issues
  • 75c58f2 test: improve test coverage from 81.2% to 90.9%
  • b350239 docs: update CHANGELOG for v0.8.0 release

- Fix Shutdown() not working: store http.Server in Application struct
- Add RunListener() method for custom listener support
- Fix Config.merge() panic on nil config: add nil check
- Add MaxRequestBodySize config to prevent DoS attacks via large request bodies
- Change Run() return type from void to error for better error handling
- Add sync.Pool for Context reuse to reduce GC pressure
- Change EnableDebug default to false for production safety
- Remove global logger, each Application gets its own Logger instance
- Fix X-Forwarded-For parsing to extract first IP from comma-separated list
- Use standard log package in util.go instead of removed global logger
- Logger middleware now uses ctx.App.Logger instead of fmt.Printf
- Add cachedMiddlewares to Group to avoid repeated slice allocations
- Add RunGraceful() method for graceful shutdown with signal handling
- Mark ParamString() and QueryString() as deprecated
- Replace interface{} with any for Go 1.18+ consistency
- Use dynamic port allocation in tests to avoid conflicts
- Remove unused isValidHTTPMethod function and its tests
- Add tests for Shutdown and RunGraceful methods
- Add tests for Logger middleware
- Add tests for remoteAddr with various headers
- Add tests for router search functionality
- Add tests for response flush with cookies and redirect
- Add tests for XML, context data, cookies, headers, queries
- Add tests for success/fail responses and body operations
- Fix acquireContext to initialize data field for sync.Pool
- Add coverage_test.go with comprehensive test cases
@kk0829
kk0829 merged commit ef14734 into main Mar 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants