Hello everyone, the GoFrame framework has officially released version v2.5.0 today! 👏👏👏👏

This version mainly focuses on improvements to existing functional components and development tools, including:

  • The development tool introduces a new gf gen ctrl command to standardize the definition and development of API interfaces, and generate code for controllers and SDKs to improve development efficiency, addressing issues of interface standardization and efficiency in Golang project development. For details, please refer to: Controller Generating.
  • The existing gf gen dao command adds a TypeMapping feature, allowing developers to customize the Golang type of entity object properties generated from database tables: Dao/Do/Entity Generating

For other changes, please refer to the following change log. Enjoy! 🍺🍺🍺🍺🍺🍺🍺🍺

Github ChangeLog: https://github.com/gogf/gf/releases/tag/v2.5.0

Full code changes: v2.4.0…v2.5.0, thanks to all the contributing developers for this release:

v2.5 2023-07-17 - 图1

Feature Improvements

  1. gdb
    1. Improved ORM SQL logging, with operations executed according to the order defined in the table fields.
    2. Improved HOOK method implementation, now supports modifying the Table field in the in parameter to change the executed table name.
    3. Added AllAndCount/ScanAndCount methods for convenient pagination query scenarios.
    4. Added Model.WhereOrNot/WhereOrPrefixNot condition methods.
  2. gi18n
    1. Improved support for Chinese ( Unicode ) as key names for translation.
  3. gclient
    1. Added Discovery chain operation method for setting service discovery components for the current request.
  4. ghttp
    1. Improved request Context processing, where each change in Context will affect the underlying http.Request object. This supports custom HTTP Handler data interaction scenarios.
    2. Added support for Endpoints configuration item to customize the service registration discovery address of the Server, allowing the use of the currently listening address.
  5. goai
    1. Improved parameter validation recognition, marking required parameters in the OpenAPIv3 results.
  6. gsel
    1. Fixed locking mechanism issues for Endpoints updates in the RoundRobin implementation.
  7. glog
    1. Added TimeFormat configuration for customizing the time format of log output: Logging - Configuration
    2. Improved Rotation implementation to support log file splitting for short-running programs.
  8. gtag
    1. Added GetGlobalEnums method to obtain globally registered enum types.
  9. gutil
    1. Added DumpJson method to format and print any type of variable to the terminal in JSON, making it easier for human reading.
  10. gvalid
    1. Added enums validation rule for automatic recognition and validation of enum types: Data Validation - Rules

Community Components

  1. Fixed load balancing issue of contrib/registry/polaris component when there are multiple servers.
  2. Improved contrib/drivers/pgsql to have the Index field in TableFields return start uniformly from 0.
  3. Improved contrib/nosql/redis with added user configuration support.
  4. Improved contrib/rpc/grpcx component, with the addition of Endpoints configuration support for grpcx.Server, enabling customizable service registration discovery addresses.
  5. Added contrib/sdk/httpclient component, dependent library for HTTP SDK code files generated by the newly added gf gen ctrl command in this version.
  6. Added contrib/trace/otlpgrpc and contrib/trace/otlphttp components for unified connection of tracing based on OpenTelemetry.

Development Tools

  1. Added gf gen ctrl command for compiling api definition directories, automatically generating standardized controller, HTTP SDK code: Controller Generating
  2. Improved gf gen dao command, added TypeMapping feature, allowing developers to customize the mapping of data table field types and generated Go entity data structure property types, and conveniently introduce third-party package types (such as decimal package for high-precision types): Dao/Do/Entity Generating
  3. Improved gf gen enums command, changed Prefix parameter to Prefixes to support specifying prefixes for multiple generated enum type packages: Enums Maintenance
  4. Improved gf gen service command:
    • Added method comment generation in the generated service file.
    • When there is an import conflict in the generated service file, automatically generate import alias.
  5. Improved command-line packaging, exposing gfcmd.Command type for developers to extend custom command-line functions.
  6. Improved gf docker command, setting build file parameters as non-mandatory (for compatibility), which will be used only for Docker builds in the future without coupling binary build functions. For full build requirements, it is recommended to use it with gf build. Updated make image command in the project template, using gf build+gf docker commands.
  7. Improved gf init command, fixed issues in some scenarios where initializing projects covered existing .git/.gitignore directories and files or permission errors.
  8. Improved gf up command, fixed issues with framework version updates in certain scenarios, and installation problems under the windows system.
  9. Improved gf version command, fixed issues with framework version recognition in some scenarios.
  10. Fixed gf gen pbentity command, modifying the float32/float64/[]byte types in the generated proto file entity data structure to float/double/bytes types.
  11. Improved development tools, some commands do not need to explicitly configure importPrefix parameter, such as: gf gen dao/service

Compatibility Notice

  1. In ghttp.Request, the Context and the context.Context returned by GetCtx method have removed the nesting of NeverDoneCtx, meaning the ctx context object passed by default in the controller fully inherits from the ctx in the standard library’s http.Request. The Done method will be automatically called to terminate it at the end of a request, and this ctx cannot be propagated to async processes that need further execution. Therefore, starting with this version, users might encounter the following two issues:
    • To propagate to async processes or maintain compatibility with previous logic: Add a middleware that calls r.SetCtx(r.GetNeverDoneCtx()) to globally override the subsequent ctx usage with a never-ending ctx.

v2.5 2023-07-17 - 图2

  • When the client actively cancels the request, the server might encounter a context canceled error. This is normal, and when the client no longer needs the request result, it will cancel the request, continuing to execute on the server-side makes no sense. If you mind this error, you can refer to the middleware above to add NeverDoneCtx, and the server will ignore the client’s cancel and continue to execute.