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 inGolang
project development. For details, please refer to: Controller Generating. - The existing
gf gen dao
command adds aTypeMapping
feature, allowing developers to customize theGolang
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:
Feature Improvements
gdb
- Improved
ORM SQL
logging, with operations executed according to the order defined in the table fields. - Improved
HOOK
method implementation, now supports modifying theTable
field in thein
parameter to change the executed table name. - Added
AllAndCount/ScanAndCount
methods for convenient pagination query scenarios. - Added
Model.WhereOrNot/WhereOrPrefixNot
condition methods.
- Improved
gi18n
- Improved support for Chinese (
Unicode
) as key names for translation.
- Improved support for Chinese (
gclient
- Added
Discovery
chain operation method for setting service discovery components for the current request.
- Added
ghttp
- Improved request
Context
processing, where each change inContext
will affect the underlyinghttp.Request
object. This supports customHTTP Handler
data interaction scenarios. - Added support for
Endpoints
configuration item to customize the service registration discovery address of theServer
, allowing the use of the currently listening address.
- Improved request
goai
- Improved parameter validation recognition, marking required parameters in the
OpenAPIv3
results.
- Improved parameter validation recognition, marking required parameters in the
gsel
- Fixed locking mechanism issues for
Endpoints
updates in theRoundRobin
implementation.
- Fixed locking mechanism issues for
glog
- Added
TimeFormat
configuration for customizing the time format of log output: Logging - Configuration - Improved
Rotation
implementation to support log file splitting for short-running programs.
- Added
gtag
- Added
GetGlobalEnums
method to obtain globally registered enum types.
- Added
gutil
- Added
DumpJson
method to format and print any type of variable to the terminal inJSON
, making it easier for human reading.
- Added
gvalid
- Added
enums
validation rule for automatic recognition and validation of enum types: Data Validation - Rules
- Added
Community Components
- Fixed load balancing issue of
contrib/registry/polaris
component when there are multiple servers. - Improved
contrib/drivers/pgsql
to have theIndex
field inTableFields
return start uniformly from0
. - Improved
contrib/nosql/redis
with added user configuration support. - Improved
contrib/rpc/grpcx
component, with the addition ofEndpoints
configuration support forgrpcx.Server
, enabling customizable service registration discovery addresses. - Added
contrib/sdk/httpclient
component, dependent library forHTTP SDK
code files generated by the newly addedgf gen ctrl
command in this version. - Added
contrib/trace/otlpgrpc
andcontrib/trace/otlphttp
components for unified connection of tracing based onOpenTelemetry
.
Development Tools
- Added
gf gen ctrl
command for compilingapi
definition directories, automatically generating standardizedcontroller
,HTTP SDK
code: Controller Generating - Improved
gf gen dao
command, addedTypeMapping
feature, allowing developers to customize the mapping of data table field types and generatedGo
entity data structure property types, and conveniently introduce third-party package types (such asdecimal
package for high-precision types): Dao/Do/Entity Generating - Improved
gf gen enums
command, changedPrefix
parameter toPrefixes
to support specifying prefixes for multiple generated enum type packages: Enums Maintenance - Improved
gf gen service
command:- Added method comment generation in the generated
service
file. - When there is an
import
conflict in the generatedservice
file, automatically generateimport alias
.
- Added method comment generation in the generated
- Improved command-line packaging, exposing
gfcmd.Command
type for developers to extend custom command-line functions. - Improved
gf docker
command, setting build file parameters as non-mandatory (for compatibility), which will be used only forDocker
builds in the future without coupling binary build functions. For full build requirements, it is recommended to use it withgf build
. Updatedmake image
command in the project template, usinggf build+gf docker
commands. - Improved
gf init
command, fixed issues in some scenarios where initializing projects covered existing.git/.gitignore
directories and files or permission errors. - Improved
gf up
command, fixed issues with framework version updates in certain scenarios, and installation problems under thewindows
system. - Improved
gf version
command, fixed issues with framework version recognition in some scenarios. - Fixed
gf gen pbentity
command, modifying thefloat32/float64/[]byte
types in the generatedproto
file entity data structure tofloat/double/bytes
types. - Improved development tools, some commands do not need to explicitly configure
importPrefix
parameter, such as:gf gen dao/service
Compatibility Notice
- In
ghttp.Request
, theContext
and thecontext.Context
returned byGetCtx
method have removed the nesting ofNeverDoneCtx
, meaning thectx
context object passed by default in the controller fully inherits from thectx
in the standard library’shttp.Request
. TheDone
method will be automatically called to terminate it at the end of a request, and thisctx
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 subsequentctx
usage with a never-endingctx
.
- To propagate to async processes or maintain compatibility with previous logic: Add a middleware that calls
- 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 addNeverDoneCtx
, and the server will ignore the client’s cancel and continue to execute.