v0.2.9
Release Notes - LessGo v0.2.9
Overview
We are excited to announce the release of LessGo v0.2.9! This update introduces several new features and improvements to enhance the functionality and robustness of your web applications.
New Features
-
Enhanced Response Handling
ctx.JSON(status int, v interface{})
: Simplify sending JSON responses with automatic content-type setting and status code handling.ctx.Error(status int, message string)
: Streamline error responses with a standardized JSON format for errors.ctx.Send(v any)
: Send plain text responses with customizable content-type settings.
-
Parameter Access
- Query Parameters: Retrieve all query parameters from the request as a JSON object with
ctx.GetAllQuery()
. - Path Parameters: Access all URL parameters with
ctx.GetAllParams()
.
- Query Parameters: Retrieve all query parameters from the request as a JSON object with
-
Cookie Management
ctx.SetCookie(name, value string, maxAge int, path string)
: Set cookies with customizable options.ctx.GetCookie(name string) (string, bool)
: Retrieve cookie values from the request.
-
Header Management
ctx.SetHeader(key, value string)
: Easily set custom headers for the response.
-
Response Prevention
- Prevention of Multiple Responses: Once a response is sent, further attempts to send additional data or headers are now prevented, ensuring that only one response is processed per request. This helps avoid issues with multiple responses or inconsistent output.
-
Static File Serving
ServeStatic(prefix string, folderPath string)
: Abstract static file serving into a reusable function, making it easier to serve static files from your application.
Example Usage
-
Sending JSON Response:
ctx.JSON(http.StatusOK, map[string]string{"message": "success"})
-
Error Handling:
ctx.Error(http.StatusBadRequest, "Invalid request")
-
Sending Plain Text:
ctx.Send("Hello, world!")
-
Query and Path Parameters:
params, _ := ctx.GetAllParams() queryParams, _ := ctx.GetAllQuery()
-
Cookies:
ctx.SetCookie("session_id", "123456", 3600, "/") value, ok := ctx.GetCookie("session_id")
-
Custom Headers:
ctx.SetHeader("X-Custom-Header", "MyValue")
-
Static File Serving:
r.ServeStatic("/static/", "path/to/content/dir")
Bug Fixes and Improvements
- Fixed issues related to handling multiple responses and ensuring consistent response behavior.
- Improved static file serving functionality and usability.
Thank you for using LessGo! As always, we appreciate your feedback and contributions. For more details, refer to our documentation or contact our support team.
Happy coding! 🚀
Contributors:
- Hokam Singh (@hokamsingh)
- The LessGo Community
Release Date: August 2024