From a5a7d2379297b02834c4afdc1b70a1f888ddf2cc Mon Sep 17 00:00:00 2001 From: John Guo Date: Tue, 12 Sep 2023 20:00:01 +0800 Subject: [PATCH] improve `g.Go` (#2956) --- cmd/gf/go.mod | 14 ++++----- contrib/config/apollo/go.mod | 2 +- contrib/config/kubecm/go.mod | 2 +- contrib/config/nacos/go.mod | 2 +- contrib/config/polaris/go.mod | 6 ++-- contrib/config/polaris/go.sum | 8 ++--- contrib/drivers/clickhouse/go.mod | 2 +- contrib/drivers/dm/go.mod | 2 +- contrib/drivers/mssql/go.mod | 2 +- contrib/drivers/mysql/go.mod | 2 +- contrib/drivers/oracle/go.mod | 2 +- contrib/drivers/pgsql/go.mod | 2 +- contrib/drivers/sqlite/go.mod | 2 +- contrib/drivers/sqlitecgo/go.mod | 2 +- contrib/nosql/redis/go.mod | 2 +- contrib/registry/etcd/go.mod | 2 +- contrib/registry/file/go.mod | 2 +- contrib/registry/polaris/go.mod | 6 ++-- contrib/registry/polaris/go.sum | 8 ++--- contrib/registry/zookeeper/go.mod | 2 +- contrib/rpc/grpcx/go.mod | 4 +-- contrib/sdk/httpclient/go.mod | 2 +- contrib/trace/jaeger/go.mod | 2 +- contrib/trace/otlpgrpc/go.mod | 2 +- contrib/trace/otlphttp/go.mod | 2 +- example/go.mod | 32 +++++++++---------- example/go.sum | 8 ++--- frame/g/g_func.go | 21 +++++++------ util/gutil/gutil.go | 39 ----------------------- util/gutil/gutil_goroutine.go | 32 +++++-------------- util/gutil/gutil_try_catch.go | 52 +++++++++++++++++++++++++++++++ util/gutil/gutil_z_unit_test.go | 2 +- version.go | 2 +- 33 files changed, 136 insertions(+), 136 deletions(-) create mode 100644 util/gutil/gutil_try_catch.go diff --git a/cmd/gf/go.mod b/cmd/gf/go.mod index 2d20b409b7e..3847d62f8e0 100644 --- a/cmd/gf/go.mod +++ b/cmd/gf/go.mod @@ -3,13 +3,13 @@ module github.com/gogf/gf/cmd/gf/v2 go 1.18 require ( - github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.5.3 - github.com/gogf/gf/contrib/drivers/mssql/v2 v2.5.3 - github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.3 - github.com/gogf/gf/contrib/drivers/oracle/v2 v2.5.3 - github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.5.3 - github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.5.3 - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.5.4 + github.com/gogf/gf/contrib/drivers/mssql/v2 v2.5.4 + github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.4 + github.com/gogf/gf/contrib/drivers/oracle/v2 v2.5.4 + github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.5.4 + github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.5.4 + github.com/gogf/gf/v2 v2.5.4 github.com/minio/selfupdate v0.6.0 github.com/olekukonko/tablewriter v0.0.5 golang.org/x/mod v0.9.0 diff --git a/contrib/config/apollo/go.mod b/contrib/config/apollo/go.mod index 7a3f2d43e14..817dc255708 100644 --- a/contrib/config/apollo/go.mod +++ b/contrib/config/apollo/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/apolloconfig/agollo/v4 v4.1.1 - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/v2 v2.5.4 ) require ( diff --git a/contrib/config/kubecm/go.mod b/contrib/config/kubecm/go.mod index ee6cdb316cc..f0fa204bd91 100644 --- a/contrib/config/kubecm/go.mod +++ b/contrib/config/kubecm/go.mod @@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/kubecm/v2 go 1.19 require ( - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/v2 v2.5.4 k8s.io/api v0.27.4 k8s.io/apimachinery v0.27.4 k8s.io/client-go v0.27.4 diff --git a/contrib/config/nacos/go.mod b/contrib/config/nacos/go.mod index a5e620d579c..8f2811eef42 100644 --- a/contrib/config/nacos/go.mod +++ b/contrib/config/nacos/go.mod @@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/nacos/v2 go 1.18 require ( - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/v2 v2.5.4 github.com/nacos-group/nacos-sdk-go v1.1.4 ) diff --git a/contrib/config/polaris/go.mod b/contrib/config/polaris/go.mod index 5e77345d701..28c2b78d2cd 100644 --- a/contrib/config/polaris/go.mod +++ b/contrib/config/polaris/go.mod @@ -3,8 +3,8 @@ module github.com/gogf/gf/contrib/config/polaris/v2 go 1.18 require ( - github.com/gogf/gf/v2 v2.5.3 - github.com/polarismesh/polaris-go v1.5.1 + github.com/gogf/gf/v2 v2.5.4 + github.com/polarismesh/polaris-go v1.5.3 ) require ( @@ -33,7 +33,7 @@ require ( github.com/natefinch/lumberjack v2.0.0+incompatible // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/polarismesh/specification v1.3.2-alpha.2 // indirect + github.com/polarismesh/specification v1.4.0 // indirect github.com/prometheus/client_golang v1.12.2 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.32.1 // indirect diff --git a/contrib/config/polaris/go.sum b/contrib/config/polaris/go.sum index 573364ca3cd..9b489b4708b 100644 --- a/contrib/config/polaris/go.sum +++ b/contrib/config/polaris/go.sum @@ -400,10 +400,10 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polarismesh/polaris-go v1.5.1 h1:EiAOYITCoa8YCigZhWefClEbqVj8MF7mTrLD3dlKIyM= -github.com/polarismesh/polaris-go v1.5.1/go.mod h1:45nx/yegSRFJ5mGITumX5FMLaY7ltrT68HVkTs9pPlk= -github.com/polarismesh/specification v1.3.2-alpha.2 h1:cMghyvCnRVM5ca2kYCGHOgIIxVnokiMvw0720q8a8RA= -github.com/polarismesh/specification v1.3.2-alpha.2/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU= +github.com/polarismesh/polaris-go v1.5.3 h1:RL1m6FThsYCzKYGOLp5HXNCnzeqa5NEsgO0h5kxZXRM= +github.com/polarismesh/polaris-go v1.5.3/go.mod h1:KVMjcp6P2R8MFPKfBPX3kzykyzH0iX8fHCiITcqKda8= +github.com/polarismesh/specification v1.4.0 h1:fm7sUtFZC2g9+lLmRCtjGrUow47CY5JDFoZXwwCQGGY= +github.com/polarismesh/specification v1.4.0/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= diff --git a/contrib/drivers/clickhouse/go.mod b/contrib/drivers/clickhouse/go.mod index 93869fa34c9..dccd1a6e13d 100644 --- a/contrib/drivers/clickhouse/go.mod +++ b/contrib/drivers/clickhouse/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/ClickHouse/clickhouse-go/v2 v2.0.15 - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/v2 v2.5.4 github.com/google/uuid v1.3.0 github.com/shopspring/decimal v1.3.1 ) diff --git a/contrib/drivers/dm/go.mod b/contrib/drivers/dm/go.mod index c658303c5b6..2c4c223956d 100644 --- a/contrib/drivers/dm/go.mod +++ b/contrib/drivers/dm/go.mod @@ -6,7 +6,7 @@ replace github.com/gogf/gf/v2 => ../../../ require ( gitee.com/chunanyong/dm v1.8.10 - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/v2 v2.5.4 ) require ( diff --git a/contrib/drivers/mssql/go.mod b/contrib/drivers/mssql/go.mod index 4029e8cf636..7a2976067b7 100644 --- a/contrib/drivers/mssql/go.mod +++ b/contrib/drivers/mssql/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/denisenkom/go-mssqldb v0.12.3 - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/v2 v2.5.4 ) require ( diff --git a/contrib/drivers/mysql/go.mod b/contrib/drivers/mysql/go.mod index e83822164c0..10018dcf501 100644 --- a/contrib/drivers/mysql/go.mod +++ b/contrib/drivers/mysql/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/go-sql-driver/mysql v1.7.1 - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/v2 v2.5.4 ) require ( diff --git a/contrib/drivers/oracle/go.mod b/contrib/drivers/oracle/go.mod index f377364ca0e..d4dcc423a7d 100644 --- a/contrib/drivers/oracle/go.mod +++ b/contrib/drivers/oracle/go.mod @@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/oracle/v2 go 1.18 require ( - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/v2 v2.5.4 github.com/sijms/go-ora/v2 v2.7.10 ) diff --git a/contrib/drivers/pgsql/go.mod b/contrib/drivers/pgsql/go.mod index 00f4f2f8d8b..9e3ff114e91 100644 --- a/contrib/drivers/pgsql/go.mod +++ b/contrib/drivers/pgsql/go.mod @@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/pgsql/v2 go 1.18 require ( - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/v2 v2.5.4 github.com/lib/pq v1.10.9 ) diff --git a/contrib/drivers/sqlite/go.mod b/contrib/drivers/sqlite/go.mod index fadb46e69f7..6f361291115 100644 --- a/contrib/drivers/sqlite/go.mod +++ b/contrib/drivers/sqlite/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/glebarez/go-sqlite v1.21.2 - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/v2 v2.5.4 ) require ( diff --git a/contrib/drivers/sqlitecgo/go.mod b/contrib/drivers/sqlitecgo/go.mod index 91892b4b683..d3f129fbdd9 100644 --- a/contrib/drivers/sqlitecgo/go.mod +++ b/contrib/drivers/sqlitecgo/go.mod @@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/sqlitecgo/v2 go 1.18 require ( - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/v2 v2.5.4 github.com/mattn/go-sqlite3 v1.14.17 ) diff --git a/contrib/nosql/redis/go.mod b/contrib/nosql/redis/go.mod index c5d314eba15..ffa46f07ca3 100644 --- a/contrib/nosql/redis/go.mod +++ b/contrib/nosql/redis/go.mod @@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/nosql/redis/v2 go 1.18 require ( - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/v2 v2.5.4 github.com/redis/go-redis/v9 v9.0.5 go.opentelemetry.io/otel v1.14.0 go.opentelemetry.io/otel/trace v1.14.0 diff --git a/contrib/registry/etcd/go.mod b/contrib/registry/etcd/go.mod index 5ea13697c27..877c6e6daaf 100644 --- a/contrib/registry/etcd/go.mod +++ b/contrib/registry/etcd/go.mod @@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/registry/etcd/v2 go 1.18 require ( - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/v2 v2.5.4 go.etcd.io/etcd/client/v3 v3.5.7 ) diff --git a/contrib/registry/file/go.mod b/contrib/registry/file/go.mod index 185071d1ae6..3b791f425b6 100644 --- a/contrib/registry/file/go.mod +++ b/contrib/registry/file/go.mod @@ -2,7 +2,7 @@ module github.com/gogf/gf/contrib/registry/file/v2 go 1.18 -require github.com/gogf/gf/v2 v2.5.3 +require github.com/gogf/gf/v2 v2.5.4 require ( github.com/BurntSushi/toml v1.2.0 // indirect diff --git a/contrib/registry/polaris/go.mod b/contrib/registry/polaris/go.mod index 61d27d328f0..6bbfb4600f1 100644 --- a/contrib/registry/polaris/go.mod +++ b/contrib/registry/polaris/go.mod @@ -3,8 +3,8 @@ module github.com/gogf/gf/contrib/registry/polaris/v2 go 1.18 require ( - github.com/gogf/gf/v2 v2.5.3 - github.com/polarismesh/polaris-go v1.5.1 + github.com/gogf/gf/v2 v2.5.4 + github.com/polarismesh/polaris-go v1.5.3 ) require ( @@ -33,7 +33,7 @@ require ( github.com/natefinch/lumberjack v2.0.0+incompatible // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/polarismesh/specification v1.3.2-alpha.2 // indirect + github.com/polarismesh/specification v1.4.0 // indirect github.com/prometheus/client_golang v1.12.2 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.32.1 // indirect diff --git a/contrib/registry/polaris/go.sum b/contrib/registry/polaris/go.sum index 573364ca3cd..9b489b4708b 100644 --- a/contrib/registry/polaris/go.sum +++ b/contrib/registry/polaris/go.sum @@ -400,10 +400,10 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polarismesh/polaris-go v1.5.1 h1:EiAOYITCoa8YCigZhWefClEbqVj8MF7mTrLD3dlKIyM= -github.com/polarismesh/polaris-go v1.5.1/go.mod h1:45nx/yegSRFJ5mGITumX5FMLaY7ltrT68HVkTs9pPlk= -github.com/polarismesh/specification v1.3.2-alpha.2 h1:cMghyvCnRVM5ca2kYCGHOgIIxVnokiMvw0720q8a8RA= -github.com/polarismesh/specification v1.3.2-alpha.2/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU= +github.com/polarismesh/polaris-go v1.5.3 h1:RL1m6FThsYCzKYGOLp5HXNCnzeqa5NEsgO0h5kxZXRM= +github.com/polarismesh/polaris-go v1.5.3/go.mod h1:KVMjcp6P2R8MFPKfBPX3kzykyzH0iX8fHCiITcqKda8= +github.com/polarismesh/specification v1.4.0 h1:fm7sUtFZC2g9+lLmRCtjGrUow47CY5JDFoZXwwCQGGY= +github.com/polarismesh/specification v1.4.0/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= diff --git a/contrib/registry/zookeeper/go.mod b/contrib/registry/zookeeper/go.mod index d6338916ff2..4f31671bcbf 100644 --- a/contrib/registry/zookeeper/go.mod +++ b/contrib/registry/zookeeper/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/go-zookeeper/zk v1.0.3 - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/v2 v2.5.4 golang.org/x/sync v0.3.0 ) diff --git a/contrib/rpc/grpcx/go.mod b/contrib/rpc/grpcx/go.mod index 5d74b74cd7e..a27467a451e 100644 --- a/contrib/rpc/grpcx/go.mod +++ b/contrib/rpc/grpcx/go.mod @@ -3,8 +3,8 @@ module github.com/gogf/gf/contrib/rpc/grpcx/v2 go 1.18 require ( - github.com/gogf/gf/contrib/registry/file/v2 v2.5.3 - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/contrib/registry/file/v2 v2.5.4 + github.com/gogf/gf/v2 v2.5.4 go.opentelemetry.io/otel v1.14.0 go.opentelemetry.io/otel/trace v1.14.0 google.golang.org/grpc v1.57.0 diff --git a/contrib/sdk/httpclient/go.mod b/contrib/sdk/httpclient/go.mod index 8781a9d0b9a..ed6ec088e97 100644 --- a/contrib/sdk/httpclient/go.mod +++ b/contrib/sdk/httpclient/go.mod @@ -2,7 +2,7 @@ module github.com/gogf/gf/contrib/sdk/httpclient/v2 go 1.18 -require github.com/gogf/gf/v2 v2.5.3 +require github.com/gogf/gf/v2 v2.5.4 require ( github.com/BurntSushi/toml v1.2.0 // indirect diff --git a/contrib/trace/jaeger/go.mod b/contrib/trace/jaeger/go.mod index 2b2d9198197..58c7edc2c6b 100644 --- a/contrib/trace/jaeger/go.mod +++ b/contrib/trace/jaeger/go.mod @@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/trace/jaeger/v2 go 1.18 require ( - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/v2 v2.5.4 go.opentelemetry.io/otel v1.14.0 go.opentelemetry.io/otel/exporters/jaeger v1.14.0 go.opentelemetry.io/otel/sdk v1.14.0 diff --git a/contrib/trace/otlpgrpc/go.mod b/contrib/trace/otlpgrpc/go.mod index 40ad103d124..05348979f4a 100644 --- a/contrib/trace/otlpgrpc/go.mod +++ b/contrib/trace/otlpgrpc/go.mod @@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/trace/otlpgrpc/v2 go 1.20 require ( - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/v2 v2.5.4 go.opentelemetry.io/otel v1.16.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.16.0 diff --git a/contrib/trace/otlphttp/go.mod b/contrib/trace/otlphttp/go.mod index 16409985655..1dc6722c1c8 100644 --- a/contrib/trace/otlphttp/go.mod +++ b/contrib/trace/otlphttp/go.mod @@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/trace/otlphttp/v2 go 1.20 require ( - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/v2 v2.5.4 go.opentelemetry.io/otel v1.16.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.16.0 diff --git a/example/go.mod b/example/go.mod index 2c9be391626..2524028fb23 100644 --- a/example/go.mod +++ b/example/go.mod @@ -3,22 +3,22 @@ module github.com/gogf/gf/example go 1.18 require ( - github.com/gogf/gf/contrib/config/apollo/v2 v2.5.3 - github.com/gogf/gf/contrib/config/kubecm/v2 v2.5.3 - github.com/gogf/gf/contrib/config/nacos/v2 v2.5.3 - github.com/gogf/gf/contrib/config/polaris/v2 v2.5.3 - github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.3 - github.com/gogf/gf/contrib/nosql/redis/v2 v2.5.3 - github.com/gogf/gf/contrib/registry/etcd/v2 v2.5.3 - github.com/gogf/gf/contrib/registry/file/v2 v2.5.3 - github.com/gogf/gf/contrib/registry/polaris/v2 v2.5.3 - github.com/gogf/gf/contrib/rpc/grpcx/v2 v2.5.3 - github.com/gogf/gf/contrib/trace/jaeger/v2 v2.5.3 - github.com/gogf/gf/contrib/trace/otlpgrpc/v2 v2.5.3 - github.com/gogf/gf/contrib/trace/otlphttp/v2 v2.5.3 - github.com/gogf/gf/v2 v2.5.3 + github.com/gogf/gf/contrib/config/apollo/v2 v2.5.4 + github.com/gogf/gf/contrib/config/kubecm/v2 v2.5.4 + github.com/gogf/gf/contrib/config/nacos/v2 v2.5.4 + github.com/gogf/gf/contrib/config/polaris/v2 v2.5.4 + github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.4 + github.com/gogf/gf/contrib/nosql/redis/v2 v2.5.4 + github.com/gogf/gf/contrib/registry/etcd/v2 v2.5.4 + github.com/gogf/gf/contrib/registry/file/v2 v2.5.4 + github.com/gogf/gf/contrib/registry/polaris/v2 v2.5.4 + github.com/gogf/gf/contrib/rpc/grpcx/v2 v2.5.4 + github.com/gogf/gf/contrib/trace/jaeger/v2 v2.5.4 + github.com/gogf/gf/contrib/trace/otlpgrpc/v2 v2.5.4 + github.com/gogf/gf/contrib/trace/otlphttp/v2 v2.5.4 + github.com/gogf/gf/v2 v2.5.4 github.com/nacos-group/nacos-sdk-go v1.1.4 - github.com/polarismesh/polaris-go v1.5.1 + github.com/polarismesh/polaris-go v1.5.3 google.golang.org/grpc v1.57.0 google.golang.org/protobuf v1.31.0 k8s.io/client-go v0.27.4 @@ -79,7 +79,7 @@ require ( github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/pelletier/go-toml v1.2.0 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/polarismesh/specification v1.3.2-alpha.2 // indirect + github.com/polarismesh/specification v1.4.0 // indirect github.com/prometheus/client_golang v1.12.2 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.32.1 // indirect diff --git a/example/go.sum b/example/go.sum index bbc2e148e63..a915cbbe158 100644 --- a/example/go.sum +++ b/example/go.sum @@ -526,10 +526,10 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polarismesh/polaris-go v1.5.1 h1:EiAOYITCoa8YCigZhWefClEbqVj8MF7mTrLD3dlKIyM= -github.com/polarismesh/polaris-go v1.5.1/go.mod h1:45nx/yegSRFJ5mGITumX5FMLaY7ltrT68HVkTs9pPlk= -github.com/polarismesh/specification v1.3.2-alpha.2 h1:cMghyvCnRVM5ca2kYCGHOgIIxVnokiMvw0720q8a8RA= -github.com/polarismesh/specification v1.3.2-alpha.2/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU= +github.com/polarismesh/polaris-go v1.5.3 h1:RL1m6FThsYCzKYGOLp5HXNCnzeqa5NEsgO0h5kxZXRM= +github.com/polarismesh/polaris-go v1.5.3/go.mod h1:KVMjcp6P2R8MFPKfBPX3kzykyzH0iX8fHCiITcqKda8= +github.com/polarismesh/specification v1.4.0 h1:fm7sUtFZC2g9+lLmRCtjGrUow47CY5JDFoZXwwCQGGY= +github.com/polarismesh/specification v1.4.0/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= diff --git a/frame/g/g_func.go b/frame/g/g_func.go index 883b0924a20..738acfadd44 100644 --- a/frame/g/g_func.go +++ b/frame/g/g_func.go @@ -17,17 +17,18 @@ import ( "github.com/gogf/gf/v2/util/gutil" ) -type ( - Func = gutil.Func // Func is the function which contains context parameter. - RecoverFunc = gutil.RecoverFunc // RecoverFunc is the panic recover function which contains context parameter. -) - // Go creates a new asynchronous goroutine function with specified recover function. // // The parameter `recoverFunc` is called when any panic during executing of `goroutineFunc`. // If `recoverFunc` is given nil, it ignores the panic from `goroutineFunc` and no panic will // throw to parent goroutine. -func Go(ctx context.Context, goroutineFunc Func, recoverFunc RecoverFunc) { +// +// But, note that, if `recoverFunc` also throws panic, such panic will be thrown to parent goroutine. +func Go( + ctx context.Context, + goroutineFunc func(ctx context.Context), + recoverFunc func(ctx context.Context, exception error), +) { gutil.Go(ctx, goroutineFunc, recoverFunc) } @@ -87,9 +88,11 @@ func Try(ctx context.Context, try func(ctx context.Context)) (err error) { } // TryCatch implements try...catch... logistics using internal panic...recover. -// It automatically calls function `catch` if any exception occurs ans passes the exception as an error. -func TryCatch(ctx context.Context, try func(ctx context.Context), catch ...func(ctx context.Context, exception error)) { - gutil.TryCatch(ctx, try, catch...) +// It automatically calls function `catch` if any exception occurs and passes the exception as an error. +// +// But, note that, if function `catch` also throws panic, the current goroutine will panic. +func TryCatch(ctx context.Context, try func(ctx context.Context), catch func(ctx context.Context, exception error)) { + gutil.TryCatch(ctx, try, catch) } // IsNil checks whether given `value` is nil. diff --git a/util/gutil/gutil.go b/util/gutil/gutil.go index b24f1b69576..fdfcb8a138d 100644 --- a/util/gutil/gutil.go +++ b/util/gutil/gutil.go @@ -8,11 +8,8 @@ package gutil import ( - "context" - "github.com/gogf/gf/v2/errors/gcode" "reflect" - "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/internal/empty" "github.com/gogf/gf/v2/util/gconv" ) @@ -21,42 +18,6 @@ const ( dumpIndent = ` ` ) -// Throw throws out an exception, which can be caught be TryCatch or recover. -func Throw(exception interface{}) { - panic(exception) -} - -// Try implements try... logistics using internal panic...recover. -// It returns error if any exception occurs, or else it returns nil. -func Try(ctx context.Context, try func(ctx context.Context)) (err error) { - defer func() { - if exception := recover(); exception != nil { - if v, ok := exception.(error); ok && gerror.HasStack(v) { - err = v - } else { - err = gerror.NewCodef(gcode.CodeInternalPanic, "%+v", exception) - } - } - }() - try(ctx) - return -} - -// TryCatch implements try...catch... logistics using internal panic...recover. -// It automatically calls function `catch` if any exception occurs and passes the exception as an error. -func TryCatch(ctx context.Context, try func(ctx context.Context), catch ...func(ctx context.Context, exception error)) { - defer func() { - if exception := recover(); exception != nil && len(catch) > 0 { - if v, ok := exception.(error); ok && gerror.HasStack(v) { - catch[0](ctx, v) - } else { - catch[0](ctx, gerror.NewCodef(gcode.CodeInternalPanic, "%+v", exception)) - } - } - }() - try(ctx) -} - // IsEmpty checks given `value` empty or not. // It returns false if `value` is: integer(0), bool(false), slice/map(len=0), nil; // or else returns true. diff --git a/util/gutil/gutil_goroutine.go b/util/gutil/gutil_goroutine.go index 111eae4d1b6..ec45551ff21 100644 --- a/util/gutil/gutil_goroutine.go +++ b/util/gutil/gutil_goroutine.go @@ -8,38 +8,22 @@ package gutil import ( "context" - - "github.com/gogf/gf/v2/errors/gcode" - "github.com/gogf/gf/v2/errors/gerror" ) -// Func is the function which contains context parameter. -type Func func(ctx context.Context) - -// RecoverFunc is the panic recover function which contains context parameter. -type RecoverFunc func(ctx context.Context, exception error) - // Go creates a new asynchronous goroutine function with specified recover function. // // The parameter `recoverFunc` is called when any panic during executing of `goroutineFunc`. // If `recoverFunc` is given nil, it ignores the panic from `goroutineFunc` and no panic will // throw to parent goroutine. -func Go(ctx context.Context, goroutineFunc Func, recoverFunc RecoverFunc) { +// +// But, note that, if `recoverFunc` also throws panic, such panic will be thrown to parent goroutine. +func Go( + ctx context.Context, + goroutineFunc func(ctx context.Context), + recoverFunc func(ctx context.Context, exception error), +) { if goroutineFunc == nil { return } - go func() { - defer func() { - if exception := recover(); exception != nil { - if recoverFunc != nil { - if v, ok := exception.(error); ok && gerror.HasStack(v) { - recoverFunc(ctx, v) - } else { - recoverFunc(ctx, gerror.NewCodef(gcode.CodeInternalPanic, "%+v", exception)) - } - } - } - }() - goroutineFunc(ctx) - }() + go TryCatch(ctx, goroutineFunc, recoverFunc) } diff --git a/util/gutil/gutil_try_catch.go b/util/gutil/gutil_try_catch.go new file mode 100644 index 00000000000..db82a3cb0c3 --- /dev/null +++ b/util/gutil/gutil_try_catch.go @@ -0,0 +1,52 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +package gutil + +import ( + "context" + + "github.com/gogf/gf/v2/errors/gcode" + "github.com/gogf/gf/v2/errors/gerror" +) + +// Throw throws out an exception, which can be caught be TryCatch or recover. +func Throw(exception interface{}) { + panic(exception) +} + +// Try implements try... logistics using internal panic...recover. +// It returns error if any exception occurs, or else it returns nil. +func Try(ctx context.Context, try func(ctx context.Context)) (err error) { + if try == nil { + return + } + defer func() { + if exception := recover(); exception != nil { + if v, ok := exception.(error); ok && gerror.HasStack(v) { + err = v + } else { + err = gerror.NewCodef(gcode.CodeInternalPanic, "%+v", exception) + } + } + }() + try(ctx) + return +} + +// TryCatch implements `try...catch..`. logistics using internal `panic...recover`. +// It automatically calls function `catch` if any exception occurs and passes the exception as an error. +// If `catch` is given nil, it ignores the panic from `try` and no panic will throw to parent goroutine. +// +// But, note that, if function `catch` also throws panic, the current goroutine will panic. +func TryCatch(ctx context.Context, try func(ctx context.Context), catch func(ctx context.Context, exception error)) { + if try == nil { + return + } + if exception := Try(ctx, try); exception != nil && catch != nil { + catch(ctx, exception) + } +} diff --git a/util/gutil/gutil_z_unit_test.go b/util/gutil/gutil_z_unit_test.go index 2195cc21017..bc7241dbb7d 100755 --- a/util/gutil/gutil_z_unit_test.go +++ b/util/gutil/gutil_z_unit_test.go @@ -40,7 +40,7 @@ func Test_TryCatch(t *testing.T) { gtest.C(t, func(t *gtest.T) { gutil.TryCatch(ctx, func(ctx context.Context) { panic("gutil TryCatch test") - }) + }, nil) }) gtest.C(t, func(t *gtest.T) { diff --git a/version.go b/version.go index 3ff6357eb5f..bcfc5c0c71c 100644 --- a/version.go +++ b/version.go @@ -2,5 +2,5 @@ package gf const ( // VERSION is the current GoFrame version. - VERSION = "v2.5.3" + VERSION = "v2.5.4" )