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/DOfeatures- Interface-oriented design
- More detailed introduction: Engineering Design 🔥
2. Full Link Tracing Features
- Observability further: bold foresight and determination
- The framework enables
OpenTelemetryfeatures by default - The framework creates
TraceIDby default, according toOpenTelemetrygeneration 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
OpenAPIv3protocol - Automatically generates
SwaggerUIpage - 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
DBexecution 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
gvargeneric? - Extensive use of
gvargeneric in core components of the framework - The significant value of
gvargeneric 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
Handlerprocessing - 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
Writerdefault 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
Tablemethod, unified use ofModelmethod to createModelobject. -
Deprecated
Struct/Structsmethods inModel, unified use ofScanmethod to execute query results conversion toStructobject/objects array: Model Query - Scan -
Deprecated
BatchInsert/BatchReplace/BatchSavemethods, unified use ofInsert/Replace/Savemethods for implementation, internally auto-recognizing parameter type to decide single or batch write: ORM Model - Insert/Save -
Added
DoFilterinterface method for custom filtering ofSQL&ArgsbeforeORMsubmits to underlyingdriver: ORM Interface - Callback -
Added
DoCommitinterface method for custom processing beforeORMsubmitsSQL&Argsto underlyingdriver -
Added
ConvertDataForRecordinterface method for customized data conversion handling. ORM Interface - Callback -
Added
Rawmethod to buildModelobject through rawSQLstatement, followed by usingModelchaining operations and features: ORM Model - Model -
Added
Handlerfeature for customizedModelobject modification and returning newModelobject, allowing easy reuse of common logic: ORM Model - Handler -
Added
Union/UnionAllfeature for merging results of multipleSQL/Modelqueries: Model Query - Union/UnionAll -
Added
Withfeature for condition query and sort statement configuration support: Model Association - With -
Added
OnDuplicate/OnDuplicateExmethods for specifying update/do-not-update field ofSavemethods: ORM Model - Insert/Save -
Added
Wheref/WhereOrfmethods for condition passing with formatted string statement: Model Query - Where -
Added
WhereLT/WhereLTE/WhereGT/WhereGTEandWhereOrLT/WhereOrLTE/WhereOrGT/WhereOrGTEmethods for adding common comparison conditions to ORM. -
Added
WherePrefix/WhereOrPrefixmethods for adding table prefixes to condition fields, commonly used in association queries -
Added
FieldsPrefix/FieldsExPrefixmethods for adding custom table prefix to query fields, commonly used in association queries -
Added
FieldsCount/FieldsSum/FieldsMin/FieldsMax/FieldsAvgmethods for adding common unified query conditions -
Added
LeftJoinOnField/RightJoinOnField/InnerJoinOnFieldmethods for convenient association with tables having the same field name -
Added
OmitEmptyWhere/OmitEmptyDatamethods for specifically filtering empty value data inWhereconditions andData: ORM Model - Fields Filtering -
Added
OmitNil/OmitNilWhere/OmitNilDatamethods for specifically filteringnildata inWhereconditions andData: ORM Model - Fields Filtering -
Added
TimeZoneconfiguration item for custom time zone conversion in database queries (currently supportsmysql/pgsql): ORM - Configuration -
Improved
Cachefeature, supports accurate cache parameter control -
Added
Closemethod for manually closing database connection -
Removed
ORMconfiguration limit of default100connections when custom configuration not used. -
Improved time maintenance feature, no longer automatically filtering
CreatedAt/UpdatedAt/DeletedAtrelated parameters submitted by developers, allowing custom updates to related time fields inORMoperations. -
Improved database execution SQL log recording, added affected row count recording
-
Interface method
HandleSqlBeforeCommitrenamed toDoCommit. -
Database method operations uniformly added
context.Contextas the first required parameter. -
Fixed
gdbcomponentWithfeature 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
goredispackage, added support forRediscluster: 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
Requestobject injection intoctxcontext object, with addedRequestFromCtx/g.RequestFromCtxmethods to obtainRequestobject inctx. - Abstracted and encapsulated
Clientfeatures intogclientcomponent: HTTPClient Serverlogs added support for printingctxcontext link information and improved log format: Link Tracing- Parameter acquisition returns unified use of
*gvar.Vargeneric object. - Deprecated direct operation methods of
HTTP Clientinghttp, must createClientobject for client access operations. - Deprecated
Controllerroute registration method, removed related implementation code. /net/gtrace- Upgraded
go.opentelemetry.io/otelto 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.Contextparameter. - Logging component added
Handlerfeature, using middleware design and supporting multipleHandlerprocessing, 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
Writerdefault off, can be enabled via related configuration: Logging - Color Printing - Deprecated
Printlnmethod. - Documentation update: Logging
- To promote observability features and implement link tracing specifications, all log printing methods added
/os/gres- Added
Exportmethod for exporting files from resource component to local disk: Resource - Methods
- Added
/os/gfile- Added
SizeFormatmethod 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.Contextcontext parameter. - Parameter acquisition returns unified use of
*gvar.Vargeneric object. - Added
Must*methods for directly obtaining parameters and triggeringpanicon 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.Vargeneric object. - All operation methods added
context.Contextcontext parameter. - Added
GetWithEnvmethod, automatically reading corresponding parameters from environment variables when they cannot be found in configuration adapter: Configuration Management - Configuration Reading - Added
GetWithCmdmethod, 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 triggeringpanicon errors. - Configuration component usability improvement, accessing configuration component via singleton object will automatically search configuration files according to
toml/yaml/yml/json/ini/xmlfile suffix: Configuration
/os/gcmd- Parameter acquisition returns unified use of
*gvar.Vargeneric 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.Vargeneric object.
- Parameter acquisition returns unified use of
/os/gcron- Added
context.Contextparameter to defined scheduled task methods. - Added
context.Contextparameter to all create scheduled task methods. - Documentation update: Cron Job
- Added
/os/gtime- Deprecated
Second/Millisecond/Microsecond/Nanosecondpackage methods, replaced withTimestamp/TimestampMilli/TimestampMicro/TimestampNanomethods. - Documentation update: Time
- Deprecated
/os/gtimer- Added
context.Contextparameter to defined timer methods. - Added
context.Contextparameter 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.Contextparameter to callback method definitions. - Added
context.Contextparameter togoroutinepool task addition methods. - Documentation update: Coroutine Management - grpool
- Added
/os/gsession- Added
ctxcontext parameter input togsession.Storageinterface for receiving context information and implementing complete link tracing. For rigor, addederrorreturn parameter: Session - Parameter acquisition returns unified use of
*gvar.Vargeneric object.
- Added
/os/gview- Added
context.Contextparameter to template parsing methods. - Added
plus/minus/times/dividearithmetic template methods. - Documentation update: Template Engine
- Added
/os/gstructs- Opened
structspackage frominternalof framework, named asgstructs, used for advanced usage ofstructreflection operations: Object Information
- Opened
4. Error Handling
-
/errors/gerror -
Added
Messagemethod for obtaining error message of specified error code. -
Added
CodeMessagemethod for obtaining error code information of specified error. -
Added
NewOptionmethod for custom-configured error object creation, dedicated to advanced players of the framework. -
Added
HasStackmethod 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
gcodecomponent introduction for details: Error Code - Example -
Improved usability, revised
NewCode/NewCodeSkip/WrapCode/WrapCodeSkipmethods, optionaltextinput parameter, default usingMessageinfo of corresponding error code. -
/errors/gcode -
Added
gcodeerror code component, providing highly customizable and extensible error code management, combined withgerrorcomponent for powerful error handling: Error Code - Example
5. Other Components
/container/garray- Added
Atmethod to each array type for directly obtaining returned data at specific index position. - Documentation update: Array - Methods
/debug/gdebug- Added
TestDataContentmethod for directly obtaining file content of specified path undertestdatadirectory in testing package. - Documentation update: Debugging
/encoding/gjson- Deprecated most
Get*methods, unified use ofGetmethod to obtain the content of specifiedpattern, uniformly returns*gvar.Vargeneric 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
ModelRawmethod for conveniently creating nativeSQLbased databaseModelobject. - Added
loggerconfiguration toORMobjects created via/frame/gmodule, auto-initialized by automatically reading configuration files: ORM - Configuration - Added
loggerconfiguration toServerobjects created via/frame/gmodule, auto-initialized by automatically reading configuration files: Configuration /frame/gmvc- Deprecated
gmvccoupled module, no further support in the future. /util/gutil- Improved implementation of
Dumpmethod, no longer usingjsonpackage to implement type printing, instead self-implemented feature for printing any type, supporting detailed data type printing: Utility Functions - Added
SliceToMapWithColumnAsKeymethod for convertingSlicetoMapaccording to certain rules. /utils/gvalid- Added
bailvalidation rule, andBailchaining method for immediately exiting validation when data validation fails and not executing subsequent validation rules. - Added
datetimevalidation 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.Contextparameter. - 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
gcmdcommand line object. - Improved
initcommand, supportsSingleRepo/MonoRepotwo repository initialization. Project initialization no longer depends on remote repository. - Improved
gen daocommand, adopting the brand newV2engineering design, automatically generatingentity/dao/docode files. - Removed
updatecommand, tool updates unified through https://github.com/gogf/gf/tree/master/cmd/gf - Removed
getcommand. - All-new documentation: CLI Tool