Main Content
GoFrame v2.9
brings several important features and improvements, including ORM
database and table sharding, transaction propagation & isolation level control, OpenAPIv3.1
support, gzip
middleware, and the new Converter
type conversion interface. These new features significantly enhance the framework's performance, scalability, and development experience.
The following are the main contents of this version. For detailed Change Log
, please refer to:
https://github.com/gogf/gf/releases/tag/v2.9.0
For complete code changes, please refer to: https://github.com/gogf/gf/compare/v2.8.0...v2.9.0
Special Thanks
💖💖💖 Thanks to all developers who contributed to this version 💖💖💖
Compatibility Notes
-
net/client
- When the global service registration and discovery component is enabled, the
HTTP Client
objects created by this component no longer enable service discovery by default. Manual activation is required.
- When the global service registration and discovery component is enabled, the
-
os/glog
- The default time printing format for logs has been adjusted to the more rigorous
2006-01-02T15:04:05.000Z07:00
.
- The default time printing format for logs has been adjusted to the more rigorous
Component Improvements
-
database/gdb
- Added ORM database and table sharding features, supporting horizontal table sharding and vertical database sharding, greatly enhancing large-scale data processing capabilities: ORM Database and Table Sharding
- Added ORM transaction propagation features, supporting transaction propagation behaviors similar to
Spring
, providing more flexible transaction management: ORM Transaction Processing - Transaction Propagation - Added ORM transaction isolation levels, supporting standard SQL transaction isolation level settings: ORM Transaction Processing - Isolation Levels
- Added ORM transaction read-only mode, optimizing read-only transaction performance: ORM Transaction Processing - Read-Only Mode
- Added
WhereExists/WhereNotExists
method support, enhancing subquery capabilities: ORM Query - Where Conditions - Added support for
unix socket
database connection configuration, providing more connection options. - Fixed an issue where using
gdb.Counter
type in theOnDuplicate
method was ineffective: ORM Chain Operation - Write and Save - Fixed an issue where when users add a
Select Hook
and modify the return structure, it causes abnormal query results inCount/Value/Array
in some scenarios. - Fixed an issue where the
orm
tag in the metadata tag ofembedded struct
in the data structure becomes ineffective when using thewith
feature. - Fixed an incompatibility issue with older versions where
tinyint(1)/int(1)
types are identified asbool
type. - Fixed an incompatibility issue with older versions in the
Order("id", "desc")
statement in thedatabase/gdb
component. - Optimized
ORM
query performance and memory usage efficiency.
-
net/ghttp
- Added common middleware
MiddlewareGzip
support for compressing return results using thegzip
algorithm, improving transmission efficiency and performance. - Added
HandlerItemParsed.GetMetaTag
method, which can be used to get the interface definition metadata information through theGetMetaTag
method after getting the current route execution method throughGetServeHandler
, enhancing route metadata management capabilities. - Removed the
*Req/*Res
naming rule restriction for input and output data structures when definingapi
in standard route registration, supporting more flexible naming methods. - Fixed an issue where the default value setting for interface parameters also takes effect when submitting empty parameters (empty string or
0
), causing inconsistency with the document description. - Fixed an issue where the logic of automatically generating
Origin
fromReferer
in cross-domain returnHeader
is not rigorous, enhancingCORS
security. - Fixed an issue where the
json omitempty
tag is ineffective when theBuildParams
method builds request parameters. - Fixed a null pointer
panic
issue that would occur whenLogger
is set tonil
, improving component stability.
- Added common middleware
-
util/gconv
- Added
Converter
conversion interface feature, supporting more flexible and extensible type conversion capabilities, providing a custom type conversion registration mechanism: Type Conversion - Converter - Added custom type conversion support, allowing developers to register custom type conversion functions: Type Conversion - Custom Type Conversion
- Improved the
Scan
method, adding support forScan
to basic data type conversion: Type Conversion - Scan Conversion - Optimized type conversion performance, improving large data volume conversion efficiency.
- Added
-
net/goai
- Support for the latest
OpenAPIv3.1
protocol specification, maintaining compatibility with mainstream API documentation tools. - Added return data structure extension capability, supporting more flexible response definitions: API Documentation - Extending Response
- Added automatic recognition of data validation rules
min/max/length/min-length/max-length/between
as corresponding validation data structures inOpenAPIv3
, simplifying document generation: API Documentation - OpenAPIv3 - Fixed an issue where the
embedded struct
data structure in parameter data structures cannot be expanded into parameter structures, improving complex data structure support. - Optimized document generation performance and memory usage.
- Support for the latest
-
net/client
- When the global service registration and discovery component is enabled, the
HTTP Client
objects created by this component no longer enable service discovery by default and need to be manually enabled: Service Registration and Discovery
- When the global service registration and discovery component is enabled, the
-
os/gcache
- Fixed an issue where the data type returned by the
Remove
method in the component is incompatible with older versions.
- Fixed an issue where the data type returned by the
-
errors/gerror
- Added
As
method support, maintaining compatibility with the standard library: Error Handling - Error Comparison
- Added
-
utils/gvalid
- Fixed an issue where
enums
validation becomes ineffective when using pointers withenums
parameters. - Fixed an issue of excessive memory usage caused by large binary content
[]byte
in parameter validation.
- Fixed an issue where
-
os/glog
- The default time printing format for logs has been adjusted to the more rigorous
2006-01-02T15:04:05.000Z07:00
.
- The default time printing format for logs has been adjusted to the more rigorous
-
os/gsession
- Added
RegenerateId/MustRegenerateId
method support for manually regeneratingSession ID
to prevent session fixation attacks: Session - RegenerateId
- Added
-
os/gview
- Fixed an issue where template files could not be read from the resource manager in some scenarios.
-
os/gcmd
- Command line parameter default values now support output to the command help interface.
-
net/gipv4
- Improved the implementation logic for converting between
ip
addresses anduint32
.
- Improved the implementation logic for converting between
-
test/gtest
- Improved
AssertNI/AssertIN
methods, addingmap
type support: Unit Testing - gtest
- Improved
Community Components
-
contrib/drivers/pgsql
- Added conversion support for
pgsql
array field typesvarchar[]/text[]
, automatically converting to Go[]string
type. - Improved array type conversion performance.
- Added conversion support for
-
contrib/config/polaris
- Added support for more data format contents, supporting formats such as
yaml/toml/json/xml/ini/properties
.
- Added support for more data format contents, supporting formats such as
-
contrib/registry/consul
- Added
consul
service registration and discovery component support: https://github.com/gogf/gf/tree/master/contrib/registry/consul
- Added
-
contrib/registry/etcd
- Added retry mechanism, solving the renewal problem when the
lease
lease expires. - Removed the default
AutoSyncInterval
configuration item, solving theetcd
blocking problem caused by this default configuration in some scenarios.
- Added retry mechanism, solving the renewal problem when the
-
contrib/registry/zookeeper
- Fixed an error in the component where service name paths with additional suffix
-
were incorrectly monitored.
- Fixed an error in the component where service name paths with additional suffix
-
contrib/config/nacos
- Added
OnChange
callback configuration support.
- Added
-
contrib/metric/otelmetric
- Added
WithExemplarFilter
option support.
- Added
Development Tools
- Improved the
gf init
command, changing the template content for initializing projects, with no change in directory structure. - Improved the
gf up
command, displaying a more elegantcli
file download interface effect in the terminal, enhancing user experience. - Improved the
gf gen ctrl
command, automatically synchronizing comments defined inapi
to the generated controller code, reducing duplicate work. - Improved the
gf gen dao
command:- Added sharding option parameter
shardingPattern/sp
for defining table sharding rules, generatingdao
code that supports database sharding, working with ORM database sharding features: Data Specification - gen dao - Improved code generation templates, supporting
Golang Template
syntax, providing more flexible code generation capabilities. - Optimized the quality and readability of generated code.
- Added sharding option parameter
- Improved the
gf gen enums
command:- Changed the default interface data structure definition directory to
api
, more in line with project specifications. - Changed the default generated code file path to
internal/packed/packed_enums.go
, optimizing code organization.
- Changed the default interface data structure definition directory to
- Improved the
gf gen genpbentity
command:- Added
TypeMapping
andFieldMapping
feature support, providing more flexible type mapping: Database Table PB - gen pbentity - Added
TablesEx
support, allowing specific tables to be ignored when generatingproto
files, increasing flexibility. - Added the
GoPackage
option for specifying thego_package
configuration item in generatedproto
files, better supporting modularization.
- Added
- Fixed an issue with the
gf build
command where environment variables were not accurately printed; it should print the actual environment variables used when compiling files after modifying environment variables. - Fixed an issue with the
gf gen pb
command where custom tags were repeatedly added after multiple executions of the command with the-a
option in some scenarios. - Fixed an issue in the
cmd/gf
component where commands in theMakefile
file generated in the project template by themake
command were incorrect. - Overall improvement in command line tool usability and stability.