Skip to content

chore: refactor to fasthttp, upgrade dependencies, improve test coverage to 96% - #23

Merged
kk0829 merged 15 commits into
mainfrom
refactor/code-optimization
Apr 1, 2026
Merged

kk0829 merged 15 commits into
mainfrom
refactor/code-optimization

Conversation

@kk0829

@kk0829 kk0829 commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR brings significant performance improvements and dependency updates:

Major Changes

  • Major: Refactor from net/http to fasthttp for better performance
  • Upgrade Go minimum version requirement to 1.25
  • Test coverage improved from 90.1% to 96.0%

Dependencies Upgraded

Package From To
fasthttp v1.52.0 v1.69.0
validator/v10 v10.12.0 v10.30.2
golang.org/x/crypto v0.19.0 v0.49.0
golang.org/x/sys v0.17.0 v0.42.0
golang.org/x/text v0.14.0 v0.35.0

Added

  • AGENTS.md with comprehensive project guidelines for AI agents
  • HTTP status code constants (StatusOK, StatusNotFound, StatusInternalServerError, etc.)
  • HTTP method constants (MethodGet, MethodPost, MethodPut, etc.)
  • MIME type constants (MIMEApplicationJSON, MIMETextHTML, etc.)
  • Header key constants (HeaderContentType, HeaderAccept, HeaderAuthorization, etc.)
  • Additional Context methods: IsAjax(), IsWebSocket(), AcceptedLanguages(), RemoteAddr()
  • Middleware caching in route groups

Performance

  • Router optimization: matchChild from O(n) to O(1)
  • Context pooling via sync.Pool for reduced GC pressure

Fixed

  • Fixed route matching issues
  • Fixed context pool reuse bug where data wasn't being reset properly
  • Fixed X-Forwarded-For header parsing for comma-separated IP addresses

- Simplify Config.merge() using explicit field assignment instead of reflection
- Optimize Context Query/Param methods, remove redundant empty string checks
- Clean up request/response struct field names (originReq->req, etc.)
- Simplify router code structure
- Add convenience methods: JSONError, IsAjax, IsWebSocket, etc.
- Replace panic with graceful error handling in Static()
- Remove deprecated ParamString and QueryString methods

BREAKING CHANGES:
- Renamed internal struct fields (originReq, paramsMap, originRes, etc.)
- Removed deprecated ParamString and QueryString methods
Add tests for new Context methods:
- JSONError, IsAjax, IsWebSocket, ContentType, AcceptedLanguages
- HTML template rendering
- File serving with error handling

Add tests for Application methods:
- Config.merge with various scenarios
- Static file serving with absolute paths
- LoadHTMLGlob and SetFuncMap
- RunGracefulShutdown and Shutdown

Add tests for Response:
- File error handling (not found, invalid path)
- Flush with cookies and redirects

Add tests for Router:
- Wildcard route matching (*filepath)
- Param extraction for multiple parameters
- Conflicting route resolution

Fix router wildcard matching bug where search would
not properly return wildcard node with pattern.
Replace Children slice with map[string]*node for constant-time
lookup in node.matchChild(). This significantly improves routing
performance when there are many sibling routes at the same level.
@kk0829 kk0829 added enhancement New feature or request dependencies Pull requests that update a dependency file labels Apr 1, 2026
@kk0829
kk0829 merged commit 6890ba7 into main Apr 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants