Hello everyone! The much-anticipated GoFrame v2
version has finally been released! This version includes a large number of improvements and new features, as well as some groundbreaking functionalities.
From last summer to this spring, we have worked hard all the way, and we hope everyone is satisfied.
Thanks to all community partners for their contributions and support from community friends!
In the new year, we continue to stay grounded, never forgetting our original intention!
Upgrade Guide: Happily Upgrade from v1 to v2
1. Important Features
1. New Engineering Design
- More rigorous and standardized
- Standardization of naming style
- Standardization of pointers and value passing parameters
- Further simplified, improving development efficiency
- New version development tools support the accurate implementation of engineering specifications
Entity/DAO/DO
features- Interface-oriented design
- More detailed introduction: Engineering Design 🔥
2. Full Link Tracing Features
- Observability further: bold foresight and determination
- The framework enables
OpenTelemetry
features by default - The framework creates
TraceID
by default, according toOpenTelemetry
generation standards - All core components of the framework support link tracing information transmission
- The logging component supports printing link information
- More detailed introduction: OpenTelemetry Tracing
3. Standardized Route Registration Features
- Standardized API structured programming design
- Standardized API interface method parameter style definition
- Simplified route registration and maintenance
- Unified interface return data format design
- Automatic API parameter object reception and validation
- Automatically generates interface documentation based on the standard
OpenAPIv3
protocol - Automatically generates
SwaggerUI
page - More detailed introduction: Standard Router
4. Full Error Stack Feature
- A major decision made at the framework level
- All framework component errors support error stacks
- Detailed introduction: Error Stack
5. New Error Code Feature
- Uses interface design, highly extensible
- Provides selectable common error codes
- Core component base layer of the framework has enhanced error code support, e.g., identifying if
DB
execution error through error code inerror
- More detailed introduction: Error Handling - Error Code
6. Component Interface Design
- Top-down unified interface design
- Core components all use interface design
- Higher extensibility and customizability
- More detailed introduction: Interface and Generic
7. Support for Generic Framework
- What is the framework
gvar
generic? - Extensive use of
gvar
generic in core components of the framework - The significant value of
gvar
generic in the framework - Why it is not recommended to use generics in top-level business
- More detailed introduction: Interface and Generic
8. Plenty of ORM Improvements
- Detailed introduction: Database ORM🔥
9. Other Important Improvements
1) Logging Component Handler
Feature
- Middleware design
- Supports multiple
Handler
processing - Provides more flexible and powerful support for developer-defined log processing
- More detailed introduction: Logging - Handler
2) Logging Component Color Printing
- Default color printing output in terminal
- Different colors for different levels by default, configurable
- Output to file/custom
Writer
default off, can be turned on via configuration - More detailed introduction: Logging - Color Printing
4) Improved Debug Mode Introduction
- More detailed introduction: Debug Mode
2. Function Improvements
1. Data Components
-
/database/gdb
-
Deprecated
Table
method, unified use ofModel
method to createModel
object. -
Deprecated
Struct/Structs
methods inModel
, unified use ofScan
method to execute query results conversion toStruct
object/objects array: Model Query - Scan -
Deprecated
BatchInsert/BatchReplace/BatchSave
methods, unified use ofInsert/Replace/Save
methods for implementation, internally auto-recognizing parameter type to decide single or batch write: ORM Model - Insert/Save -
Added
DoFilter
interface method for custom filtering ofSQL&Args
beforeORM
submits to underlyingdriver
: ORM Interface - Callback -
Added
DoCommit
interface method for custom processing beforeORM
submitsSQL&Args
to underlyingdriver
-
Added
ConvertDataForRecord
interface method for customized data conversion handling. ORM Interface - Callback -
Added
Raw
method to buildModel
object through rawSQL
statement, followed by usingModel
chaining operations and features: ORM Model - Model -
Added
Handler
feature for customizedModel
object modification and returning newModel
object, allowing easy reuse of common logic: ORM Model - Handler -
Added
Union/UnionAll
feature for merging results of multipleSQL/Model
queries: Model Query - Union/UnionAll -
Added
With
feature for condition query and sort statement configuration support: Model Association - With -
Added
OnDuplicate/OnDuplicateEx
methods for specifying update/do-not-update field ofSave
methods: ORM Model - Insert/Save -
Added
Wheref/WhereOrf
methods for condition passing with formatted string statement: Model Query - Where -
Added
WhereLT/WhereLTE/WhereGT/WhereGTE
andWhereOrLT/WhereOrLTE/WhereOrGT/WhereOrGTE
methods for adding common comparison conditions to ORM. -
Added
WherePrefix/WhereOrPrefix
methods for adding table prefixes to condition fields, commonly used in association queries -
Added
FieldsPrefix/FieldsExPrefix
methods for adding custom table prefix to query fields, commonly used in association queries -
Added
FieldsCount/FieldsSum/FieldsMin/FieldsMax/FieldsAvg
methods for adding common unified query conditions -
Added
LeftJoinOnField/RightJoinOnField/InnerJoinOnField
methods for convenient association with tables having the same field name -
Added
OmitEmptyWhere/OmitEmptyData
methods for specifically filtering empty value data inWhere
conditions andData
: ORM Model - Fields Filtering -
Added
OmitNil/OmitNilWhere/OmitNilData
methods for specifically filteringnil
data inWhere
conditions andData
: ORM Model - Fields Filtering -
Added
TimeZone
configuration item for custom time zone conversion in database queries (currently supportsmysql/pgsql
): ORM - Configuration -
Improved
Cache
feature, supports accurate cache parameter control -
Added
Close
method for manually closing database connection -
Removed
ORM
configuration limit of default100
connections when custom configuration not used. -
Improved time maintenance feature, no longer automatically filtering
CreatedAt/UpdatedAt/DeletedAt
related parameters submitted by developers, allowing custom updates to related time fields inORM
operations. -
Improved database execution SQL log recording, added affected row count recording
-
Interface method
HandleSqlBeforeCommit
renamed toDoCommit
. -
Database method operations uniformly added
context.Context
as the first required parameter. -
Fixed
gdb
componentWith
feature multi-level query invalid issue. -
Removed all deprecated methods of query result types
Record/Result
. -
Completed unit tests.
-
/database/gredis
-
Adopted adapter pattern, refactored the component with interface design to improve extensibility: Redis - Interface
-
Provided default adapter implementation based on third-party
goredis
package, added support forRedis
cluster: Redis - Configuration -
Due to support for cluster features, configuration file format changed: Redis - Configuration
2. Network Components
/net/ghttp
- New route registration method: Standard Router
- Default
Request
object injection intoctx
context object, with addedRequestFromCtx/g.RequestFromCtx
methods to obtainRequest
object inctx
. - Abstracted and encapsulated
Client
features intogclient
component: HTTPClient Server
logs added support for printingctx
context link information and improved log format: Link Tracing- Parameter acquisition returns unified use of
*gvar.Var
generic object. - Deprecated direct operation methods of
HTTP Client
inghttp
, must createClient
object for client access operations. - Deprecated
Controller
route registration method, removed related implementation code. /net/gtrace
- Upgraded
go.opentelemetry.io/otel
to the latest official version. - Improved new link tracing usage documentation: Service Tracing
3. System Components
/os/glog
- To promote observability features and implement link tracing specifications, all log printing methods added
context.Context
parameter. - Logging component added
Handler
feature, using middleware design and supporting multipleHandler
processing, providing more flexible and powerful support for developer-defined log processing: Logging - Handler - Logging component added support for color printing of content, default color printing output in terminal, output to file/custom
Writer
default off, can be enabled via related configuration: Logging - Color Printing - Deprecated
Println
method. - Documentation update: Logging
- To promote observability features and implement link tracing specifications, all log printing methods added
/os/gres
- Added
Export
method for exporting files from resource component to local disk: Resource - Methods
- Added
/os/gfile
- Added
SizeFormat
method for getting formatted size string of specified file. - Documentation update: File
- Added
/os/gcache
- Adopted adapter pattern, refactored the component with interface design to improve extensibility: Caching - Interface
- Provided default cache implementation based on process memory: Caching - In-Memory
- All operation methods added
context.Context
context parameter. - Parameter acquisition returns unified use of
*gvar.Var
generic object. - Added
Must*
methods for directly obtaining parameters and triggeringpanic
on errors.
/os/gcfg
- Adopted adapter pattern, refactored the component with interface design to improve extensibility: Configuration - Interface
- Provided default configuration management based on file system: Configuration
- Parameter acquisition returns unified use of
*gvar.Var
generic object. - All operation methods added
context.Context
context parameter. - Added
GetWithEnv
method, automatically reading corresponding parameters from environment variables when they cannot be found in configuration adapter: Configuration Management - Configuration Reading - Added
GetWithCmd
method, automatically reading corresponding parameters from command line parameters when they cannot be found in configuration adapter: Configuration Management - Configuration Reading - Added
Must*
methods for directly obtaining parameters and triggeringpanic
on errors. - Configuration component usability improvement, accessing configuration component via singleton object will automatically search configuration files according to
toml/yaml/yml/json/ini/xml
file suffix: Configuration
/os/gcmd
- Parameter acquisition returns unified use of
*gvar.Var
generic object. - Brand new multi-level command line management method, supports automatic generation of command line usage tips: Command - Object
- Added object-based command line management method, more suitable for large terminal command scenes: Command - Structure
- Parameter acquisition returns unified use of
/os/genv
- Parameter acquisition returns unified use of
*gvar.Var
generic object.
- Parameter acquisition returns unified use of
/os/gcron
- Added
context.Context
parameter to defined scheduled task methods. - Added
context.Context
parameter to all create scheduled task methods. - Documentation update: Cron Job
- Added
/os/gtime
- Deprecated
Second/Millisecond/Microsecond/Nanosecond
package methods, replaced withTimestamp/TimestampMilli/TimestampMicro/TimestampNano
methods. - Documentation update: Time
- Deprecated
/os/gtimer
- Added
context.Context
parameter to defined timer methods. - Added
context.Context
parameter to all create timer methods. - Improved the timer task execution detection mechanism based on priority queue data structure storage, enhancing execution performance.
- Documentation update: Timer
- Added
/os/grpool
- Added
context.Context
parameter to callback method definitions. - Added
context.Context
parameter togoroutine
pool task addition methods. - Documentation update: Coroutine Management - grpool
- Added
/os/gsession
- Added
ctx
context parameter input togsession.Storage
interface for receiving context information and implementing complete link tracing. For rigor, addederror
return parameter: Session - Parameter acquisition returns unified use of
*gvar.Var
generic object.
- Added
/os/gview
- Added
context.Context
parameter to template parsing methods. - Added
plus/minus/times/divide
arithmetic template methods. - Documentation update: Template Engine
- Added
/os/gstructs
- Opened
structs
package frominternal
of framework, named asgstructs
, used for advanced usage ofstruct
reflection operations: Object Information
- Opened
4. Error Handling
-
/errors/gerror
-
Added
Message
method for obtaining error message of specified error code. -
Added
CodeMessage
method for obtaining error code information of specified error. -
Added
NewOption
method for custom-configured error object creation, dedicated to advanced players of the framework. -
Added
HasStack
method to determine whether given error interface object has implemented (contains) stack information. -
Changed error code from integer to interface object to achieve customizability and improve extensibility, refer to
gcode
component introduction for details: Error Code - Example -
Improved usability, revised
NewCode/NewCodeSkip/WrapCode/WrapCodeSkip
methods, optionaltext
input parameter, default usingMessage
info of corresponding error code. -
/errors/gcode
-
Added
gcode
error code component, providing highly customizable and extensible error code management, combined withgerror
component for powerful error handling: Error Code - Example
5. Other Components
/container/garray
- Added
At
method to each array type for directly obtaining returned data at specific index position. - Documentation update: Array - Methods
/debug/gdebug
- Added
TestDataContent
method for directly obtaining file content of specified path undertestdata
directory in testing package. - Documentation update: Debugging
/encoding/gjson
- Deprecated most
Get*
methods, unified use ofGet
method to obtain the content of specifiedpattern
, uniformly returns*gvar.Var
generic object, developers can use corresponding methods to easily convert to specific type variables according to business scenario. - Added several
Must*
methods. - Comprehensive update on usage documentation
/frame/g
- Added
ModelRaw
method for conveniently creating nativeSQL
based databaseModel
object. - Added
logger
configuration toORM
objects created via/frame/g
module, auto-initialized by automatically reading configuration files: ORM - Configuration - Added
logger
configuration toServer
objects created via/frame/g
module, auto-initialized by automatically reading configuration files: Configuration /frame/gmvc
- Deprecated
gmvc
coupled module, no further support in the future. /util/gutil
- Improved implementation of
Dump
method, no longer usingjson
package to implement type printing, instead self-implemented feature for printing any type, supporting detailed data type printing: Utility Functions - Added
SliceToMapWithColumnAsKey
method for convertingSlice
toMap
according to certain rules. /utils/gvalid
- Added
bail
validation rule, andBail
chaining method for immediately exiting validation when data validation fails and not executing subsequent validation rules. - Added
datetime
validation rule for validating common date and time types, with date separator supporting only-
, format like:2006-01-02 12:00:00
. - Removed package validation methods, unified implementation of data validation using chaining operations.
- All validation methods added
context.Context
parameter. - Brand new, highly complete usage documentation of the data validation component: Data Validation
For other numerous improvement details, we won't elaborate here. Interested friends can refer to the official website goframe.org
3. CLI Toolchain
- Refactoring implemented with the encapsulation of the brand new
gcmd
command line object. - Improved
init
command, supportsSingleRepo/MonoRepo
two repository initialization. Project initialization no longer depends on remote repository. - Improved
gen dao
command, adopting the brand newV2
engineering design, automatically generatingentity/dao/do
code files. - Removed
update
command, tool updates unified through https://github.com/gogf/gf/tree/master/cmd/gf - Removed
get
command. - All-new documentation: CLI Tool