Skip to content

v0.2.9

Compare
Choose a tag to compare
@hokamsingh hokamsingh released this 21 Aug 17:10
· 95 commits to main since this release

Go-Logo_Aqua

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

  1. 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.
  2. 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().
  3. 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.
  4. Header Management

    • ctx.SetHeader(key, value string): Easily set custom headers for the response.
  5. 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.
  6. 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:

Release Date: August 2024