LessGo v0.2.8
Release Notes
We are excited to announce the release of LessGo v0.2.8, which brings several powerful new features and improvements to our lightweight, Go-based web framework. This version introduces enhanced request and response handling, streamlined routing capabilities, and more robust context management. Here's what's new:
New Features
-
Custom Context (
Context
) Integration- Enhanced Request and Response Handling: Introducing a custom
Context
structure (Context
) that provides utility methods for accessing request parameters, handling request bodies, and sending JSON responses. This makes it easier to work with HTTP requests and responses in a more expressive and convenient way. - Request Body Parsing: The
Context
now includes aBody
method to parse JSON request bodies into Go structs. This simplifies the handling of incoming data while ensuring type safety and ease of use. - JSON Response Handling: The
Context
provides aJSON
method that streamlines the process of sending JSON responses to the client. It automatically sets theContent-Type
header and encodes the response data into JSON format.
- Enhanced Request and Response Handling: Introducing a custom
-
Routing Enhancements
- Express-style HTTP Methods: LessGo now supports all standard HTTP methods (GET, POST, PUT, DELETE, etc.) directly within the router. You can now define routes using expressive methods like
r.Get
,r.Post
,r.Put
, andr.Delete
, making route definitions cleaner and more intuitive. - Route Middleware Support: The framework now supports middleware chaining for routes. Middleware functions can be applied to routes to handle tasks such as request logging, error handling, and CORS management.
- Express-style HTTP Methods: LessGo now supports all standard HTTP methods (GET, POST, PUT, DELETE, etc.) directly within the router. You can now define routes using expressive methods like
-
Request Body Persistence
- Non-destructive JSON Parsing: The framework's JSON parser middleware now reads and stores the request body without consuming it. This allows the body to be accessed multiple times, ensuring that your handlers can always access the original request data.
- Accessor for Parsed JSON Body: A new
GetJSONBody
method has been added to theContext
, allowing easy retrieval of the parsed JSON body from the request context. This provides a seamless way to work with request data across different parts of your application.
-
Utilities and Middleware
- Serve Static Files: The framework now includes improved support for serving static files, with easy-to-use methods for defining static file directories.
- Middleware Enhancements: Middleware functions for CORS, rate limiting, and JSON parsing have been refined to work seamlessly with the new context and routing features.
Bug Fixes and Improvements
- Improved Error Handling: Enhanced error handling within the context and middleware, ensuring more informative error messages and smoother request processing.
- Optimized Performance: Various optimizations to the request handling pipeline to reduce overhead and improve response times.
- Refactoring and Code Cleanup: Significant refactoring of the internal codebase for better maintainability and extensibility.
Breaking Changes
- CustomHandler to http.HandlerFunc Conversion: The introduction of custom context handling may require updates to existing handlers. Make sure to wrap existing
http.HandlerFunc
handlers using the new context-aware methods to maintain compatibility.
We hope you find these new features and improvements valuable as you continue to build with LessGo. As always, we welcome your feedback and contributions. Happy coding!
Contributors:
- Hokam Singh (@hokamsingh)
- The LessGo Community
Release Date: August 2024