From 50b04c658ce8f7bb29a11987baaa873b3c11cf74 Mon Sep 17 00:00:00 2001 From: zhonghuaxunGM <50815786+zhonghuaxunGM@users.noreply.github.com> Date: Mon, 6 Nov 2023 09:52:36 +0800 Subject: [PATCH 01/22] improve implements and fix issues for package `contrib/drivers/dm` (#3128) --- contrib/drivers/dm/dm.go | 81 ++++++++++++++++++++++++++++++--------- contrib/drivers/dm/go.mod | 2 +- 2 files changed, 63 insertions(+), 20 deletions(-) diff --git a/contrib/drivers/dm/dm.go b/contrib/drivers/dm/dm.go index a30b2087b..076c70d77 100644 --- a/contrib/drivers/dm/dm.go +++ b/contrib/drivers/dm/dm.go @@ -12,8 +12,6 @@ import ( "database/sql" "fmt" "net/url" - "reflect" - "strconv" "strings" "time" @@ -77,8 +75,8 @@ func (d *Driver) Open(config *gdb.ConfigNode) (db *sql.DB, err error) { // Data Source Name of DM8: // dm://userName:password@ip:port/dbname source = fmt.Sprintf( - "dm://%s:%s@%s:%s/%s?charset=%s", - config.User, config.Pass, config.Host, config.Port, config.Name, config.Charset, + "dm://%s:%s@%s:%s/%s?charset=%s&schema=%s", + config.User, config.Pass, config.Host, config.Port, config.Name, config.Charset, config.Name, ) // Demo of timezone setting: // &loc=Asia/Shanghai @@ -147,8 +145,9 @@ func (d *Driver) TableFields(ctx context.Context, table string, schema ...string result, err = d.DoSelect( ctx, link, fmt.Sprintf( - `SELECT * FROM ALL_TAB_COLUMNS WHERE Table_Name= '%s'`, + `SELECT * FROM ALL_TAB_COLUMNS WHERE Table_Name= '%s' AND OWNER = '%s'`, strings.ToUpper(table), + strings.ToUpper(d.GetSchema()), ), ) if err != nil { @@ -206,14 +205,53 @@ func (d *Driver) ConvertValueForField(ctx context.Context, fieldType string, fie func (d *Driver) DoFilter(ctx context.Context, link gdb.Link, sql string, args []interface{}) (newSql string, newArgs []interface{}, err error) { // There should be no need to capitalize, because it has been done from field processing before newSql, _ = gregex.ReplaceString(`["\n\t]`, "", sql) + newSql = gstr.ReplaceI(gstr.ReplaceI(newSql, "GROUP_CONCAT", "LISTAGG"), "SEPARATOR", ",") + + // TODO The current approach is too rough. We should deal with the GROUP_CONCAT function and the parsing of the index field from within the select from match. + // (GROUP_CONCAT DM does not approve; index cannot be used as a query column name, and security characters need to be added, such as "index") + l, r := d.GetChars() + newSql = gstr.ReplaceI(newSql, "INDEX", l+"INDEX"+r) + + // TODO i tried to do but it never work: + // array, err := gregex.MatchAllString(`SELECT (.*INDEX.*) FROM .*`, newSql) + // g.Dump("err:", err) + // g.Dump("array:", array) + // g.Dump("array:", array[0][1]) + + // newSql, err = gregex.ReplaceString(`SELECT (.*INDEX.*) FROM .*`, l+"INDEX"+r, newSql) + // g.Dump("err:", err) + // g.Dump("newSql:", newSql) + + // re, err := regexp.Compile(`.*SELECT (.*INDEX.*) FROM .*`) + // newSql = re.ReplaceAllStringFunc(newSql, func(data string) string { + // fmt.Println("data:", data) + // return data + // }) + return d.Core.DoFilter( ctx, link, - gstr.ReplaceI(newSql, "GROUP_CONCAT", "WM_CONCAT"), + newSql, args, ) } +// TODO I originally wanted to only convert keywords in select +// 但是我发现 DoQuery 中会对 sql 会对 " " 达梦的安全字符 进行 / 转义,最后还是导致达梦无法正常解析 +// However, I found that DoQuery() will perform / escape on sql with " " Dameng's safe characters, which ultimately caused Dameng to be unable to parse normally. +// But processing in DoFilter() is OK +// func (d *Driver) DoQuery(ctx context.Context, link gdb.Link, sql string, args ...interface{}) (gdb.Result, error) { +// l, r := d.GetChars() +// new := gstr.ReplaceI(sql, "INDEX", l+"INDEX"+r) +// g.Dump("new:", new) +// return d.Core.DoQuery( +// ctx, +// link, +// new, +// args, +// ) +// } + // DoInsert inserts or updates data forF given table. func (d *Driver) DoInsert( ctx context.Context, link gdb.Link, table string, list gdb.List, option gdb.DoInsertOption, @@ -342,22 +380,27 @@ func parseUnion(list gdb.List, char struct { if mapper[column] == nil { continue } - va := reflect.ValueOf(mapper[column]) - ty := reflect.TypeOf(mapper[column]) - switch ty.Kind() { - case reflect.String: - saveValue = append(saveValue, char.valueCharL+va.String()+char.valueCharR) + // va := reflect.ValueOf(mapper[column]) + // ty := reflect.TypeOf(mapper[column]) + // switch ty.Kind() { + // case reflect.String: + // saveValue = append(saveValue, char.valueCharL+va.String()+char.valueCharR) - case reflect.Int: - saveValue = append(saveValue, strconv.FormatInt(va.Int(), 10)) + // case reflect.Int: + // saveValue = append(saveValue, strconv.FormatInt(va.Int(), 10)) - case reflect.Int64: - saveValue = append(saveValue, strconv.FormatInt(va.Int(), 10)) + // case reflect.Int64: + // saveValue = append(saveValue, strconv.FormatInt(va.Int(), 10)) - default: - // The fish has no chance getting here. - // Nothing to do. - } + // default: + // // The fish has no chance getting here. + // // Nothing to do. + // } + saveValue = append(saveValue, + fmt.Sprintf( + char.valueCharL+"%s"+char.valueCharR, + gconv.String(mapper[column]), + )) } unionValues = append( unionValues, diff --git a/contrib/drivers/dm/go.mod b/contrib/drivers/dm/go.mod index aaee57d48..510e0c6bd 100644 --- a/contrib/drivers/dm/go.mod +++ b/contrib/drivers/dm/go.mod @@ -5,7 +5,7 @@ go 1.18 replace github.com/gogf/gf/v2 => ../../../ require ( - gitee.com/chunanyong/dm v1.8.10 + gitee.com/chunanyong/dm v1.8.12 github.com/gogf/gf/v2 v2.5.6 ) From 007fe0ea1a252834f39a51b5babbc5f6b07f1c82 Mon Sep 17 00:00:00 2001 From: oldme <45782393+oldme-git@users.noreply.github.com> Date: Mon, 6 Nov 2023 09:59:45 +0800 Subject: [PATCH 02/22] enhance #3063 (#3115) --- cmd/gf/internal/cmd/genctrl/genctrl.go | 2 +- .../testdata/genctrl/api/article/v1/edit.go | 24 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/cmd/gf/internal/cmd/genctrl/genctrl.go b/cmd/gf/internal/cmd/genctrl/genctrl.go index 5f76a4fe2..a651a3d8c 100644 --- a/cmd/gf/internal/cmd/genctrl/genctrl.go +++ b/cmd/gf/internal/cmd/genctrl/genctrl.go @@ -38,7 +38,7 @@ gf gen ctrl ) const ( - PatternApiDefinition = `type\s+(\w+)Req\s+struct\s+{([\s\S]+?)}` + PatternApiDefinition = `type[\s\(]+(\w+)Req\s+struct\s+{([\s\S]+?)}` PatternCtrlDefinition = `func\s+\(.+?\)\s+\w+\(.+?\*(\w+)\.(\w+)Req\)\s+\(.+?\*(\w+)\.(\w+)Res,\s+\w+\s+error\)\s+{` ) diff --git a/cmd/gf/internal/cmd/testdata/genctrl/api/article/v1/edit.go b/cmd/gf/internal/cmd/testdata/genctrl/api/article/v1/edit.go index b873d5804..9e893d87c 100644 --- a/cmd/gf/internal/cmd/testdata/genctrl/api/article/v1/edit.go +++ b/cmd/gf/internal/cmd/testdata/genctrl/api/article/v1/edit.go @@ -8,16 +8,20 @@ package v1 import "github.com/gogf/gf/v2/frame/g" -type CreateReq struct { - g.Meta `path:"/article/create" method:"post" tags:"ArticleService"` - Title string `v:"required"` -} +type ( + CreateReq struct { + g.Meta `path:"/article/create" method:"post" tags:"ArticleService"` + Title string `v:"required"` + } -type CreateRes struct{} + CreateRes struct{} +) -type UpdateReq struct { - g.Meta `path:"/article/update" method:"post" tags:"ArticleService"` - Title string `v:"required"` -} +type ( + UpdateReq struct { + g.Meta `path:"/article/update" method:"post" tags:"ArticleService"` + Title string `v:"required"` + } -type UpdateRes struct{} + UpdateRes struct{} +) From eb99f5ebfeea8a15516d2f50c313ac137fc07efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=B7=E4=BA=AE?= <739476267@qq.com> Date: Mon, 6 Nov 2023 19:20:07 +0800 Subject: [PATCH 03/22] rename function name `PKCS5UnPadding` to `PKCS7UnPadding` (#3124) --- crypto/gaes/gaes.go | 37 +++++++++++++++++++++++++++------ crypto/gaes/gaes_z_unit_test.go | 20 +++++++++++++++++- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/crypto/gaes/gaes.go b/crypto/gaes/gaes.go index 4e7e5e4f6..acaea665d 100644 --- a/crypto/gaes/gaes.go +++ b/crypto/gaes/gaes.go @@ -11,6 +11,7 @@ import ( "bytes" "crypto/aes" "crypto/cipher" + "fmt" "github.com/gogf/gf/v2/errors/gcode" "github.com/gogf/gf/v2/errors/gerror" @@ -41,7 +42,7 @@ func EncryptCBC(plainText []byte, key []byte, iv ...[]byte) ([]byte, error) { return nil, err } blockSize := block.BlockSize() - plainText = PKCS5Padding(plainText, blockSize) + plainText = PKCS7Padding(plainText, blockSize) ivValue := ([]byte)(nil) if len(iv) > 0 { ivValue = iv[0] @@ -80,23 +81,47 @@ func DecryptCBC(cipherText []byte, key []byte, iv ...[]byte) ([]byte, error) { blockModel := cipher.NewCBCDecrypter(block, ivValue) plainText := make([]byte, len(cipherText)) blockModel.CryptBlocks(plainText, cipherText) - plainText, e := PKCS5UnPadding(plainText, blockSize) + plainText, e := PKCS7UnPadding(plainText, blockSize) if e != nil { return nil, e } return plainText, nil } -func PKCS5Padding(src []byte, blockSize int) []byte { +// PKCS5Padding applies PKCS#5 padding to the source byte slice to match the given block size. +// +// If the block size is not provided, it defaults to 8. +func PKCS5Padding(src []byte, blockSize ...int) []byte { + blockSizeTemp := 8 + if len(blockSize) > 0 { + blockSizeTemp = blockSize[0] + } + return PKCS7Padding(src, blockSizeTemp) +} + +// PKCS5UnPadding removes PKCS#5 padding from the source byte slice based on the given block size. +// +// If the block size is not provided, it defaults to 8. +func PKCS5UnPadding(src []byte, blockSize ...int) ([]byte, error) { + blockSizeTemp := 8 + if len(blockSize) > 0 { + blockSizeTemp = blockSize[0] + } + return PKCS7UnPadding(src, blockSizeTemp) +} + +// PKCS7Padding applies PKCS#7 padding to the source byte slice to match the given block size. +func PKCS7Padding(src []byte, blockSize int) []byte { padding := blockSize - len(src)%blockSize padtext := bytes.Repeat([]byte{byte(padding)}, padding) return append(src, padtext...) } -func PKCS5UnPadding(src []byte, blockSize int) ([]byte, error) { +// PKCS7UnPadding removes PKCS#7 padding from the source byte slice based on the given block size. +func PKCS7UnPadding(src []byte, blockSize int) ([]byte, error) { length := len(src) if blockSize <= 0 { - return nil, gerror.NewCode(gcode.CodeInvalidParameter, "invalid blocklen") + return nil, gerror.NewCode(gcode.CodeInvalidParameter, fmt.Sprintf("invalid blockSize: %d", blockSize)) } if length%blockSize != 0 || length == 0 { @@ -105,7 +130,7 @@ func PKCS5UnPadding(src []byte, blockSize int) ([]byte, error) { unpadding := int(src[length-1]) if unpadding > blockSize || unpadding == 0 { - return nil, gerror.NewCode(gcode.CodeInvalidParameter, "invalid padding") + return nil, gerror.NewCode(gcode.CodeInvalidParameter, "invalid unpadding") } padding := src[length-unpadding:] diff --git a/crypto/gaes/gaes_z_unit_test.go b/crypto/gaes/gaes_z_unit_test.go index 052b39731..ca5a9a706 100644 --- a/crypto/gaes/gaes_z_unit_test.go +++ b/crypto/gaes/gaes_z_unit_test.go @@ -81,7 +81,7 @@ func TestDecrypt(t *testing.T) { t.Assert(decrypt, content) decrypt, err = gaes.Decrypt([]byte(content_32_iv), keys, iv) - t.Assert(err, "invalid padding") + t.Assert(err, "invalid unpadding") }) } @@ -128,6 +128,24 @@ func TestPKCS5UnPaddingErr(t *testing.T) { _, err = gaes.PKCS5UnPadding(key_32_err, 32) t.AssertNE(err, nil) }) + + gtest.C(t, func(t *gtest.T) { + // PKCS7UnPadding blockSize zero + _, err := gaes.PKCS7UnPadding(content, 0) + t.AssertNE(err, nil) + + // PKCS7UnPadding src len zero + _, err = gaes.PKCS7UnPadding([]byte(""), 16) + t.AssertNE(err, nil) + + // PKCS7UnPadding src len > blockSize + _, err = gaes.PKCS7UnPadding(key_17, 16) + t.AssertNE(err, nil) + + // PKCS7UnPadding src len > blockSize + _, err = gaes.PKCS7UnPadding(key_32_err, 32) + t.AssertNE(err, nil) + }) } func TestEncryptCFB(t *testing.T) { From dc71c0d28f8234a23072cd49c4bd8cba813af533 Mon Sep 17 00:00:00 2001 From: oldme <45782393+oldme-git@users.noreply.github.com> Date: Mon, 6 Nov 2023 19:27:26 +0800 Subject: [PATCH 04/22] enhance #3129 (#3134) --- .../internal/cmd/genenums/genenums_parser.go | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/cmd/gf/internal/cmd/genenums/genenums_parser.go b/cmd/gf/internal/cmd/genenums/genenums_parser.go index 5e38492c3..2cacf95d6 100644 --- a/cmd/gf/internal/cmd/genenums/genenums_parser.go +++ b/cmd/gf/internal/cmd/genenums/genenums_parser.go @@ -19,9 +19,10 @@ import ( const pkgLoadMode = 0xffffff type EnumsParser struct { - enums []EnumItem - parsedPkg map[string]struct{} - prefixes []string + enums []EnumItem + parsedPkg map[string]struct{} + prefixes []string + standardPackages map[string]struct{} } type EnumItem struct { @@ -31,23 +32,12 @@ type EnumItem struct { Type string // Pkg.ID + TypeName } -var standardPackages = make(map[string]struct{}) - -func init() { - stdPackages, err := packages.Load(nil, "std") - if err != nil { - panic(err) - } - for _, p := range stdPackages { - standardPackages[p.ID] = struct{}{} - } -} - func NewEnumsParser(prefixes []string) *EnumsParser { return &EnumsParser{ - enums: make([]EnumItem, 0), - parsedPkg: make(map[string]struct{}), - prefixes: prefixes, + enums: make([]EnumItem, 0), + parsedPkg: make(map[string]struct{}), + prefixes: prefixes, + standardPackages: getStandardPackages(), } } @@ -59,7 +49,7 @@ func (p *EnumsParser) ParsePackages(pkgs []*packages.Package) { func (p *EnumsParser) ParsePackage(pkg *packages.Package) { // Ignore std packages. - if _, ok := standardPackages[pkg.ID]; ok { + if _, ok := p.standardPackages[pkg.ID]; ok { return } // Ignore pared packages. @@ -144,3 +134,15 @@ func (p *EnumsParser) Export() string { } return gjson.MustEncodeString(typeEnumMap) } + +func getStandardPackages() map[string]struct{} { + standardPackages := make(map[string]struct{}) + stdPackages, err := packages.Load(nil, "std") + if err != nil { + panic(err) + } + for _, p := range stdPackages { + standardPackages[p.ID] = struct{}{} + } + return standardPackages +} From f3e3a5af5aa356521b36faa9af900c0c03640161 Mon Sep 17 00:00:00 2001 From: houseme Date: Wed, 8 Nov 2023 21:16:23 +0800 Subject: [PATCH 05/22] feat: improve code for shutdown of otel (#3136) --- contrib/trace/otlpgrpc/otlpgrpc.go | 17 ++++++++++++++--- contrib/trace/otlphttp/otlphttp.go | 17 ++++++++++++++--- example/trace/grpc_with_db/client/client.go | 4 ++-- example/trace/grpc_with_db/server/server.go | 4 ++-- example/trace/http/client/client.go | 4 ++-- example/trace/http/server/server.go | 4 ++-- example/trace/http_with_db/client/client.go | 4 ++-- example/trace/http_with_db/server/server.go | 4 ++-- example/trace/inprocess/main.go | 4 ++-- example/trace/otlp/grpc/main.go | 4 ++-- example/trace/otlp/http/main.go | 4 ++-- 11 files changed, 46 insertions(+), 24 deletions(-) diff --git a/contrib/trace/otlpgrpc/otlpgrpc.go b/contrib/trace/otlpgrpc/otlpgrpc.go index b602116cb..6c9ae2993 100644 --- a/contrib/trace/otlpgrpc/otlpgrpc.go +++ b/contrib/trace/otlpgrpc/otlpgrpc.go @@ -9,8 +9,8 @@ package otlpgrpc import ( "context" + "time" - "github.com/gogf/gf/v2/net/gipv4" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/otlp/otlptrace" @@ -20,6 +20,9 @@ import ( sdktrace "go.opentelemetry.io/otel/sdk/trace" semconv "go.opentelemetry.io/otel/semconv/v1.20.0" "google.golang.org/grpc" + + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/gipv4" ) const ( @@ -30,7 +33,7 @@ const ( // // The output parameter `Shutdown` is used for waiting exported trace spans to be uploaded, // which is useful if your program is ending, and you do not want to lose recent spans. -func Init(serviceName, endpoint, traceToken string) (*sdktrace.TracerProvider, error) { +func Init(serviceName, endpoint, traceToken string) (func(), error) { // Try retrieving host ip for tracing info. var ( intranetIPArray, err = gipv4.GetIntranetIpArray() @@ -87,5 +90,13 @@ func Init(serviceName, endpoint, traceToken string) (*sdktrace.TracerProvider, e otel.SetTextMapPropagator(propagation.TraceContext{}) otel.SetTracerProvider(tracerProvider) - return tracerProvider, nil + return func() { + ctx, cancel := context.WithTimeout(ctx, time.Second) + defer cancel() + if err = traceExp.Shutdown(ctx); err != nil { + g.Log().Errorf(ctx, "Shutdown traceExp failed err:%+v", err) + otel.Handle(err) + } + g.Log().Debug(ctx, "Shutdown traceExp success") + }, nil } diff --git a/contrib/trace/otlphttp/otlphttp.go b/contrib/trace/otlphttp/otlphttp.go index a4c2d210b..5778074d4 100644 --- a/contrib/trace/otlphttp/otlphttp.go +++ b/contrib/trace/otlphttp/otlphttp.go @@ -9,8 +9,8 @@ package otlphttp import ( "context" + "time" - "github.com/gogf/gf/v2/net/gipv4" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/otlp/otlptrace" @@ -19,6 +19,9 @@ import ( "go.opentelemetry.io/otel/sdk/resource" sdktrace "go.opentelemetry.io/otel/sdk/trace" semconv "go.opentelemetry.io/otel/semconv/v1.20.0" + + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/gipv4" ) const ( @@ -29,7 +32,7 @@ const ( // // The output parameter `Shutdown` is used for waiting exported trace spans to be uploaded, // which is useful if your program is ending, and you do not want to lose recent spans. -func Init(serviceName, endpoint, path string) (*sdktrace.TracerProvider, error) { +func Init(serviceName, endpoint, path string) (func(), error) { // Try retrieving host ip for tracing info. var ( intranetIPArray, err = gipv4.GetIntranetIpArray() @@ -85,5 +88,13 @@ func Init(serviceName, endpoint, path string) (*sdktrace.TracerProvider, error) otel.SetTextMapPropagator(propagation.TraceContext{}) otel.SetTracerProvider(tracerProvider) - return tracerProvider, nil + return func() { + ctx, cancel := context.WithTimeout(ctx, time.Second) + defer cancel() + if err = traceExp.Shutdown(ctx); err != nil { + g.Log().Errorf(ctx, "Shutdown traceExp failed err:%+v", err) + otel.Handle(err) + } + g.Log().Debug(ctx, "Shutdown traceExp success") + }, nil } diff --git a/example/trace/grpc_with_db/client/client.go b/example/trace/grpc_with_db/client/client.go index 8ad147a53..c1b4fcb11 100644 --- a/example/trace/grpc_with_db/client/client.go +++ b/example/trace/grpc_with_db/client/client.go @@ -20,11 +20,11 @@ func main() { grpcx.Resolver.Register(etcd.New("127.0.0.1:2379")) var ctx = gctx.New() - tp, err := otlpgrpc.Init(serviceName, endpoint, traceToken) + shutdown, err := otlpgrpc.Init(serviceName, endpoint, traceToken) if err != nil { g.Log().Fatal(ctx, err) } - defer tp.Shutdown(ctx) + defer shutdown() StartRequests() } diff --git a/example/trace/grpc_with_db/server/server.go b/example/trace/grpc_with_db/server/server.go index 5a938ce2e..0a55f2e6b 100644 --- a/example/trace/grpc_with_db/server/server.go +++ b/example/trace/grpc_with_db/server/server.go @@ -33,11 +33,11 @@ func main() { grpcx.Resolver.Register(etcd.New("127.0.0.1:2379")) var ctx = gctx.New() - tp, err := otlpgrpc.Init(serviceName, endpoint, traceToken) + shutdown, err := otlpgrpc.Init(serviceName, endpoint, traceToken) if err != nil { g.Log().Fatal(ctx, err) } - defer tp.Shutdown(ctx) + defer shutdown() // Set ORM cache adapter with redis. g.DB().GetCache().SetAdapter(gcache.NewAdapterRedis(g.Redis())) diff --git a/example/trace/http/client/client.go b/example/trace/http/client/client.go index 5ebb7cf52..254f47c08 100644 --- a/example/trace/http/client/client.go +++ b/example/trace/http/client/client.go @@ -15,11 +15,11 @@ const ( func main() { var ctx = gctx.New() - tp, err := otlphttp.Init(serviceName, endpoint, path) + shutdown, err := otlphttp.Init(serviceName, endpoint, path) if err != nil { g.Log().Fatal(ctx, err) } - defer tp.Shutdown(ctx) + defer shutdown() StartRequests() } diff --git a/example/trace/http/server/server.go b/example/trace/http/server/server.go index eb0a5be8c..2e734ace3 100644 --- a/example/trace/http/server/server.go +++ b/example/trace/http/server/server.go @@ -16,11 +16,11 @@ const ( func main() { var ctx = gctx.New() - tp, err := otlphttp.Init(serviceName, endpoint, path) + shutdown, err := otlphttp.Init(serviceName, endpoint, path) if err != nil { g.Log().Fatal(ctx, err) } - defer tp.Shutdown(ctx) + defer shutdown() s := g.Server() s.Group("/", func(group *ghttp.RouterGroup) { diff --git a/example/trace/http_with_db/client/client.go b/example/trace/http_with_db/client/client.go index bcf766610..676d4de9b 100644 --- a/example/trace/http_with_db/client/client.go +++ b/example/trace/http_with_db/client/client.go @@ -17,11 +17,11 @@ const ( func main() { var ctx = gctx.New() - tp, err := otlphttp.Init(serviceName, endpoint, path) + shutdown, err := otlphttp.Init(serviceName, endpoint, path) if err != nil { g.Log().Fatal(ctx, err) } - defer tp.Shutdown(ctx) + defer shutdown() StartRequests() } diff --git a/example/trace/http_with_db/server/server.go b/example/trace/http_with_db/server/server.go index 3057f7fd6..7c4139a50 100644 --- a/example/trace/http_with_db/server/server.go +++ b/example/trace/http_with_db/server/server.go @@ -24,11 +24,11 @@ const ( func main() { var ctx = gctx.New() - tp, err := otlphttp.Init(serviceName, endpoint, path) + shutdown, err := otlphttp.Init(serviceName, endpoint, path) if err != nil { g.Log().Fatal(ctx, err) } - defer tp.Shutdown(ctx) + defer shutdown() // Set ORM cache adapter with redis. g.DB().GetCache().SetAdapter(gcache.NewAdapterRedis(g.Redis())) diff --git a/example/trace/inprocess/main.go b/example/trace/inprocess/main.go index ad25fa60a..b792094bb 100644 --- a/example/trace/inprocess/main.go +++ b/example/trace/inprocess/main.go @@ -18,11 +18,11 @@ const ( func main() { var ctx = gctx.New() - tp, err := otlphttp.Init(serviceName, endpoint, path) + shutdown, err := otlphttp.Init(serviceName, endpoint, path) if err != nil { g.Log().Fatal(ctx, err) } - defer tp.Shutdown(ctx) + defer shutdown() ctx, span := gtrace.NewSpan(ctx, "main") defer span.End() diff --git a/example/trace/otlp/grpc/main.go b/example/trace/otlp/grpc/main.go index 726c1743d..224ee5fdc 100644 --- a/example/trace/otlp/grpc/main.go +++ b/example/trace/otlp/grpc/main.go @@ -22,11 +22,11 @@ const ( func main() { var ctx = gctx.New() - tp, err := otlpgrpc.Init(serviceName, endpoint, traceToken) + shutdown, err := otlpgrpc.Init(serviceName, endpoint, traceToken) if err != nil { g.Log().Fatal(ctx, err) } - defer tp.Shutdown(ctx) + defer shutdown() StartRequests() } diff --git a/example/trace/otlp/http/main.go b/example/trace/otlp/http/main.go index 673ebe9d4..b1ad9e5fc 100644 --- a/example/trace/otlp/http/main.go +++ b/example/trace/otlp/http/main.go @@ -21,11 +21,11 @@ const ( func main() { var ctx = gctx.New() - tp, err := otlphttp.Init(serviceName, endpoint, path) + shutdown, err := otlphttp.Init(serviceName, endpoint, path) if err != nil { g.Log().Fatal(ctx, err) } - defer tp.Shutdown(ctx) + defer shutdown() StartRequests() } From a17849bc39c482480b4db45441251e3e065a80c1 Mon Sep 17 00:00:00 2001 From: John Guo Date: Wed, 8 Nov 2023 21:17:55 +0800 Subject: [PATCH 06/22] improve struct converting in parameter name case sensitive scenario for package `gconv` (#3122) --- net/ghttp/ghttp_request_param.go | 2 + ...ghttp_z_unit_feature_router_strict_test.go | 42 ++++++++ util/gconv/gconv_struct.go | 96 +++++++++++++++++-- 3 files changed, 133 insertions(+), 7 deletions(-) diff --git a/net/ghttp/ghttp_request_param.go b/net/ghttp/ghttp_request_param.go index a3084542b..806428ae4 100644 --- a/net/ghttp/ghttp_request_param.go +++ b/net/ghttp/ghttp_request_param.go @@ -158,6 +158,8 @@ func (r *Request) GetBody() []byte { return r.bodyContent } +// MakeBodyRepeatableRead marks the request body could be repeatedly readable or not. +// It also returns the current content of the request body. func (r *Request) MakeBodyRepeatableRead(repeatableRead bool) []byte { if r.bodyContent == nil { var err error diff --git a/net/ghttp/ghttp_z_unit_feature_router_strict_test.go b/net/ghttp/ghttp_z_unit_feature_router_strict_test.go index b3f1479ba..b528f4863 100644 --- a/net/ghttp/ghttp_z_unit_feature_router_strict_test.go +++ b/net/ghttp/ghttp_z_unit_feature_router_strict_test.go @@ -377,3 +377,45 @@ func Test_Router_Handler_Strict_WithGeneric(t *testing.T) { t.Assert(client.GetContent(ctx, "/test3_slice?age=3"), `{"code":0,"message":"","data":[{"Test":3}]}`) }) } + +type ParameterCaseSensitiveController struct{} + +type ParameterCaseSensitiveControllerPathReq struct { + g.Meta `path:"/api/*path" method:"post"` + Path string +} + +type ParameterCaseSensitiveControllerPathRes struct { + Path string +} + +func (c *ParameterCaseSensitiveController) Path( + ctx context.Context, + req *ParameterCaseSensitiveControllerPathReq, +) (res *ParameterCaseSensitiveControllerPathRes, err error) { + return &ParameterCaseSensitiveControllerPathRes{Path: req.Path}, nil +} + +func Test_Router_Handler_Strict_ParameterCaseSensitive(t *testing.T) { + s := g.Server(guid.S()) + s.Use(ghttp.MiddlewareHandlerResponse) + s.Group("/", func(group *ghttp.RouterGroup) { + group.Bind(&ParameterCaseSensitiveController{}) + }) + s.SetDumpRouterMap(false) + s.Start() + defer s.Shutdown() + + time.Sleep(100 * time.Millisecond) + gtest.C(t, func(t *gtest.T) { + client := g.Client() + client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())) + + for i := 0; i < 1000; i++ { + t.Assert( + client.PostContent(ctx, "/api/111", `{"Path":"222"}`), + `{"code":0,"message":"","data":{"Path":"222"}}`, + ) + } + }) +} diff --git a/util/gconv/gconv_struct.go b/util/gconv/gconv_struct.go index 2c6433584..b3554ba55 100644 --- a/util/gconv/gconv_struct.go +++ b/util/gconv/gconv_struct.go @@ -228,10 +228,12 @@ func doStruct(params interface{}, pointer interface{}, mapping map[string]string // The key of the attrMap is the attribute name of the struct, // and the value is its replaced name for later comparison to improve performance. var ( - tempName string - elemFieldType reflect.StructField - elemFieldValue reflect.Value - elemType = pointerElemReflectValue.Type() + tempName string + elemFieldType reflect.StructField + elemFieldValue reflect.Value + elemType = pointerElemReflectValue.Type() + // Attribute name to its symbols-removed name, + // in order to quick index and comparison in following logic. attrToCheckNameMap = make(map[string]string) ) for i := 0; i < pointerElemReflectValue.NumField(); i++ { @@ -290,7 +292,84 @@ func doStruct(params interface{}, pointer interface{}, mapping map[string]string paramsMap[attributeName] = paramsMap[tagName] } } + // To convert value base on precise attribute name. + err = doStructBaseOnAttribute( + pointerElemReflectValue, + paramsMap, + mapping, + doneMap, + attrToCheckNameMap, + ) + if err != nil { + return err + } + // Already done all attributes value assignment nothing to do next. + if len(doneMap) == len(attrToCheckNameMap) { + return nil + } + // To convert value base on parameter map. + err = doStructBaseOnParamMap( + pointerElemReflectValue, + paramsMap, + mapping, + doneMap, + attrToCheckNameMap, + attrToTagCheckNameMap, + tagToAttrNameMap, + ) + if err != nil { + return err + } + return nil +} +func doStructBaseOnAttribute( + pointerElemReflectValue reflect.Value, + paramsMap map[string]interface{}, + mapping map[string]string, + doneMap map[string]struct{}, + attrToCheckNameMap map[string]string, +) error { + var customMappingAttrMap = make(map[string]struct{}) + if len(mapping) > 0 { + for paramName := range paramsMap { + if passedAttrKey, ok := mapping[paramName]; ok { + customMappingAttrMap[passedAttrKey] = struct{}{} + } + } + } + for attrName := range attrToCheckNameMap { + // The value by precise attribute name. + paramValue, ok := paramsMap[attrName] + if !ok { + continue + } + // If the attribute name is in custom mapping, it then ignores this converting. + if _, ok = customMappingAttrMap[attrName]; ok { + continue + } + // If the attribute name is already checked converting, then skip it. + if _, ok = doneMap[attrName]; ok { + continue + } + // Mark it done. + doneMap[attrName] = struct{}{} + if err := bindVarToStructAttr(pointerElemReflectValue, attrName, paramValue, mapping); err != nil { + return err + } + } + return nil +} + +func doStructBaseOnParamMap( + pointerElemReflectValue reflect.Value, + paramsMap map[string]interface{}, + mapping map[string]string, + doneMap map[string]struct{}, + attrToCheckNameMap map[string]string, + attrToTagCheckNameMap map[string]string, + tagToAttrNameMap map[string]string, +) error { var ( attrName string checkName string @@ -344,12 +423,12 @@ func doStruct(params interface{}, pointer interface{}, mapping map[string]string continue } // If the attribute name is already checked converting, then skip it. - if _, ok = doneMap[attrName]; ok { + if _, ok := doneMap[attrName]; ok { continue } // Mark it done. doneMap[attrName] = struct{}{} - if err = bindVarToStructAttr(pointerElemReflectValue, attrName, paramValue, mapping); err != nil { + if err := bindVarToStructAttr(pointerElemReflectValue, attrName, paramValue, mapping); err != nil { return err } } @@ -357,7 +436,10 @@ func doStruct(params interface{}, pointer interface{}, mapping map[string]string } // bindVarToStructAttr sets value to struct object attribute by name. -func bindVarToStructAttr(structReflectValue reflect.Value, attrName string, value interface{}, mapping map[string]string) (err error) { +func bindVarToStructAttr( + structReflectValue reflect.Value, + attrName string, value interface{}, mapping map[string]string, +) (err error) { structFieldValue := structReflectValue.FieldByName(attrName) if !structFieldValue.IsValid() { return nil From 5f5b82188cd7248a6cb2500358009cbb6b7fbae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=B7=E4=BA=AE?= <739476267@qq.com> Date: Wed, 8 Nov 2023 21:23:39 +0800 Subject: [PATCH 07/22] example: log rotate (#3137) --- example/os/log/rotate/config.toml | 8 ++++++++ example/os/log/rotate/main.go | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 example/os/log/rotate/config.toml create mode 100644 example/os/log/rotate/main.go diff --git a/example/os/log/rotate/config.toml b/example/os/log/rotate/config.toml new file mode 100644 index 000000000..623e47935 --- /dev/null +++ b/example/os/log/rotate/config.toml @@ -0,0 +1,8 @@ +[logger] +path = "./log" +file = "{Y-m-d-H-i}.log" +level = "all" +stdout = true +rotateExpire = "1m" +rotateBackupLimit = 4 +rotateCheckInterval = "5s" diff --git a/example/os/log/rotate/main.go b/example/os/log/rotate/main.go new file mode 100644 index 000000000..5a3fcbf2f --- /dev/null +++ b/example/os/log/rotate/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "context" + "time" + + "github.com/gogf/gf/v2/frame/g" +) + +func main() { + ctx := context.Background() + mylog := g.Log() + for { + mylog.Debug(ctx, "debug") + time.Sleep(time.Second) + mylog.Info(ctx, "info") + time.Sleep(time.Second) + mylog.Warning(ctx, "warning") + time.Sleep(time.Second) + mylog.Error(ctx, "error") + time.Sleep(time.Second) + } +} From 0b407c5e6d2dcc9094e26281f265077aa5c3a472 Mon Sep 17 00:00:00 2001 From: Hunk Zhu Date: Wed, 8 Nov 2023 21:26:51 +0800 Subject: [PATCH 08/22] fix "gf gen pb" api and ctrl not working well. (#3076) --- contrib/drivers/clickhouse/clickhouse.go | 2 +- contrib/drivers/mysql/mysql_model_test.go | 2 +- contrib/drivers/sqlite/sqlite_model_test.go | 2 +- contrib/drivers/sqlitecgo/sqlite_model_test.go | 2 +- database/gdb/gdb_core.go | 6 +++--- database/gdb/gdb_core_config.go | 6 +++--- database/gdb/gdb_model_select.go | 2 +- database/gdb/gdb_model_time.go | 12 ++++++------ database/gdb/gdb_type_result_scanlist.go | 6 +++--- os/gcmd/gcmd_command.go | 11 ++++++----- os/gcmd/gcmd_command_object.go | 7 ++++++- os/gcmd/gcmd_command_run.go | 8 +++++--- os/gcmd/gcmd_z_unit_feature_object1_test.go | 15 ++++++++++++++- util/gconv/gconv_scan.go | 6 +++--- 14 files changed, 54 insertions(+), 33 deletions(-) diff --git a/contrib/drivers/clickhouse/clickhouse.go b/contrib/drivers/clickhouse/clickhouse.go index 059e9afff..33665c0eb 100644 --- a/contrib/drivers/clickhouse/clickhouse.go +++ b/contrib/drivers/clickhouse/clickhouse.go @@ -163,7 +163,7 @@ func (d *Driver) TableFields(ctx context.Context, table string, schema ...string isNull = false fieldType = m["type"].String() ) - // in clickhouse , filed type like is Nullable(int) + // in clickhouse , field type like is Nullable(int) fieldsResult, _ := gregex.MatchString(`^Nullable\((.*?)\)`, fieldType) if len(fieldsResult) == 2 { isNull = true diff --git a/contrib/drivers/mysql/mysql_model_test.go b/contrib/drivers/mysql/mysql_model_test.go index 0aa8d494a..230100f76 100644 --- a/contrib/drivers/mysql/mysql_model_test.go +++ b/contrib/drivers/mysql/mysql_model_test.go @@ -4118,7 +4118,7 @@ func Test_Model_Embedded_Filter(t *testing.T) { // Password string // Nickname string // CreateTime string -// NoneExistFiled string +// NoneExistField string // } // data := User{ // Id: 1, diff --git a/contrib/drivers/sqlite/sqlite_model_test.go b/contrib/drivers/sqlite/sqlite_model_test.go index cd260bc57..f39804f1e 100644 --- a/contrib/drivers/sqlite/sqlite_model_test.go +++ b/contrib/drivers/sqlite/sqlite_model_test.go @@ -3726,7 +3726,7 @@ func Test_Model_Insert_KeyFieldNameMapping_Error(t *testing.T) { Password string Nickname string CreateTime string - NoneExistFiled string + NoneExistField string } data := User{ Id: 1, diff --git a/contrib/drivers/sqlitecgo/sqlite_model_test.go b/contrib/drivers/sqlitecgo/sqlite_model_test.go index c47bccd12..8aa297e7a 100644 --- a/contrib/drivers/sqlitecgo/sqlite_model_test.go +++ b/contrib/drivers/sqlitecgo/sqlite_model_test.go @@ -3765,7 +3765,7 @@ func Test_Model_Insert_KeyFieldNameMapping_Error(t *testing.T) { Password string Nickname string CreateTime string - NoneExistFiled string + NoneExistField string } data := User{ Id: 1, diff --git a/database/gdb/gdb_core.go b/database/gdb/gdb_core.go index 43db34735..f4ac5f781 100644 --- a/database/gdb/gdb_core.go +++ b/database/gdb/gdb_core.go @@ -785,7 +785,7 @@ func (c *Core) HasTable(name string) (bool, error) { return result.Bool(), nil } -// isSoftCreatedFieldName checks and returns whether given filed name is an automatic-filled created time. +// isSoftCreatedFieldName checks and returns whether given field name is an automatic-filled created time. func (c *Core) isSoftCreatedFieldName(fieldName string) bool { if fieldName == "" { return false @@ -794,9 +794,9 @@ func (c *Core) isSoftCreatedFieldName(fieldName string) bool { if utils.EqualFoldWithoutChars(fieldName, config.CreatedAt) { return true } - return gstr.InArray(append([]string{config.CreatedAt}, createdFiledNames...), fieldName) + return gstr.InArray(append([]string{config.CreatedAt}, createdFieldNames...), fieldName) } - for _, v := range createdFiledNames { + for _, v := range createdFieldNames { if utils.EqualFoldWithoutChars(fieldName, v) { return true } diff --git a/database/gdb/gdb_core_config.go b/database/gdb/gdb_core_config.go index 1b2edca5a..149d2afc3 100644 --- a/database/gdb/gdb_core_config.go +++ b/database/gdb/gdb_core_config.go @@ -49,9 +49,9 @@ type ConfigNode struct { ExecTimeout time.Duration `json:"execTimeout"` // (Optional) Max exec time for dml. TranTimeout time.Duration `json:"tranTimeout"` // (Optional) Max exec time for a transaction. PrepareTimeout time.Duration `json:"prepareTimeout"` // (Optional) Max exec time for prepare operation. - CreatedAt string `json:"createdAt"` // (Optional) The filed name of table for automatic-filled created datetime. - UpdatedAt string `json:"updatedAt"` // (Optional) The filed name of table for automatic-filled updated datetime. - DeletedAt string `json:"deletedAt"` // (Optional) The filed name of table for automatic-filled updated datetime. + CreatedAt string `json:"createdAt"` // (Optional) The field name of table for automatic-filled created datetime. + UpdatedAt string `json:"updatedAt"` // (Optional) The field name of table for automatic-filled updated datetime. + DeletedAt string `json:"deletedAt"` // (Optional) The field name of table for automatic-filled updated datetime. TimeMaintainDisabled bool `json:"timeMaintainDisabled"` // (Optional) Disable the automatic time maintaining feature. } diff --git a/database/gdb/gdb_model_select.go b/database/gdb/gdb_model_select.go index c7f7239d3..de19b8d62 100644 --- a/database/gdb/gdb_model_select.go +++ b/database/gdb/gdb_model_select.go @@ -306,7 +306,7 @@ func (m *Model) Scan(pointer interface{}, where ...interface{}) error { // Where("u1.id<2"). // ScanAndCount(&users, &count, false) func (m *Model) ScanAndCount(pointer interface{}, totalCount *int, useFieldForCount bool) (err error) { - // support Fileds with *, example: .Fileds("a.*, b.name"). Count sql is select count(1) from xxx + // support Fields with *, example: .Fields("a.*, b.name"). Count sql is select count(1) from xxx countModel := m.Clone() // If useFieldForCount is false, set the fields to a constant value of 1 for counting if !useFieldForCount { diff --git a/database/gdb/gdb_model_time.go b/database/gdb/gdb_model_time.go index cd3671fcc..76333ba65 100644 --- a/database/gdb/gdb_model_time.go +++ b/database/gdb/gdb_model_time.go @@ -17,9 +17,9 @@ import ( ) var ( - createdFiledNames = []string{"created_at", "create_at"} // Default filed names of table for automatic-filled created datetime. - updatedFiledNames = []string{"updated_at", "update_at"} // Default filed names of table for automatic-filled updated datetime. - deletedFiledNames = []string{"deleted_at", "delete_at"} // Default filed names of table for automatic-filled deleted datetime. + createdFieldNames = []string{"created_at", "create_at"} // Default field names of table for automatic-filled created datetime. + updatedFieldNames = []string{"updated_at", "update_at"} // Default field names of table for automatic-filled updated datetime. + deletedFieldNames = []string{"deleted_at", "delete_at"} // Default field names of table for automatic-filled deleted datetime. ) // Unscoped disables the auto-update time feature for insert, update and delete options. @@ -47,7 +47,7 @@ func (m *Model) getSoftFieldNameCreated(schema string, table string) string { if config.CreatedAt != "" { return m.getSoftFieldName(schema, tableName, []string{config.CreatedAt}) } - return m.getSoftFieldName(schema, tableName, createdFiledNames) + return m.getSoftFieldName(schema, tableName, createdFieldNames) } // getSoftFieldNameUpdate checks and returns the field name for record updating time. @@ -68,7 +68,7 @@ func (m *Model) getSoftFieldNameUpdated(schema string, table string) (field stri if config.UpdatedAt != "" { return m.getSoftFieldName(schema, tableName, []string{config.UpdatedAt}) } - return m.getSoftFieldName(schema, tableName, updatedFiledNames) + return m.getSoftFieldName(schema, tableName, updatedFieldNames) } // getSoftFieldNameDelete checks and returns the field name for record deleting time. @@ -89,7 +89,7 @@ func (m *Model) getSoftFieldNameDeleted(schema string, table string) (field stri if config.DeletedAt != "" { return m.getSoftFieldName(schema, tableName, []string{config.DeletedAt}) } - return m.getSoftFieldName(schema, tableName, deletedFiledNames) + return m.getSoftFieldName(schema, tableName, deletedFieldNames) } // getSoftFieldName retrieves and returns the field name of the table for possible key. diff --git a/database/gdb/gdb_type_result_scanlist.go b/database/gdb/gdb_type_result_scanlist.go index 84210c07d..d2d322846 100644 --- a/database/gdb/gdb_type_result_scanlist.go +++ b/database/gdb/gdb_type_result_scanlist.go @@ -247,7 +247,7 @@ func doScanList(in doScanListInput) (err error) { relationBindToFieldName string // Eg: relationKV: id:uid -> uid ) if len(in.RelationFields) > 0 { - // The relation key string of table filed name and attribute name + // The relation key string of table field name and attribute name // can be joined with char '=' or ':'. array := gstr.SplitAndTrim(in.RelationFields, "=") if len(array) == 1 { @@ -363,11 +363,11 @@ func doScanList(in doScanListInput) (err error) { if in.RelationFields != "" && !relationBindToFieldNameChecked { relationFromAttrField = relationFromAttrValue.FieldByName(relationBindToFieldName) if !relationFromAttrField.IsValid() { - filedMap, _ := gstructs.FieldMap(gstructs.FieldMapInput{ + fieldMap, _ := gstructs.FieldMap(gstructs.FieldMapInput{ Pointer: relationFromAttrValue, RecursiveOption: gstructs.RecursiveOptionEmbeddedNoTag, }) - if key, _ := gutil.MapPossibleItemByKey(gconv.Map(filedMap), relationBindToFieldName); key == "" { + if key, _ := gutil.MapPossibleItemByKey(gconv.Map(fieldMap), relationBindToFieldName); key == "" { return gerror.NewCodef( gcode.CodeInvalidParameter, `cannot find possible related attribute name "%s" from given relation fields "%s"`, diff --git a/os/gcmd/gcmd_command.go b/os/gcmd/gcmd_command.go index 557a7531c..d3cfc2b78 100644 --- a/os/gcmd/gcmd_command.go +++ b/os/gcmd/gcmd_command.go @@ -42,11 +42,12 @@ type FuncWithValue func(ctx context.Context, parser *Parser) (out interface{}, e // Argument is the command value that are used by certain command. type Argument struct { - Name string // Option name. - Short string // Option short. - Brief string // Brief info about this Option, which is used in help info. - IsArg bool // IsArg marks this argument taking value from command line argument instead of option. - Orphan bool // Whether this Option having or having no value bound to it. + Name string // Option name. + FieldName string // Option field name. + Short string // Option short. + Brief string // Brief info about this Option, which is used in help info. + IsArg bool // IsArg marks this argument taking value from command line argument instead of option. + Orphan bool // Whether this Option having or having no value bound to it. } var ( diff --git a/os/gcmd/gcmd_command_object.go b/os/gcmd/gcmd_command_object.go index e8bd99177..ab9d3d7cb 100644 --- a/os/gcmd/gcmd_command_object.go +++ b/os/gcmd/gcmd_command_object.go @@ -144,7 +144,7 @@ func newCommandFromObjectMeta(object interface{}, name string) (command *Command if err = gconv.Scan(metaData, &command); err != nil { return } - // Name filed is necessary. + // Name field is necessary. if command.Name == "" { if name == "" { err = gerror.Newf( @@ -353,6 +353,9 @@ func newArgumentsFromInput(object interface{}) (args []Argument, err error) { } if arg.Name == "" { arg.Name = field.Name() + } else if arg.Name != field.Name() { + arg.FieldName = field.Name() + nameSet.Add(arg.FieldName) } if arg.Name == helpOptionName { return nil, gerror.Newf( @@ -414,6 +417,8 @@ func mergeDefaultStructValue(data map[string]interface{}, pointer interface{}) e } else { if utils.IsEmpty(foundValue) { data[foundKey] = field.TagValue + } else { + data[field.Name()] = foundValue } } } diff --git a/os/gcmd/gcmd_command_run.go b/os/gcmd/gcmd_command_run.go index c3f6fd53c..7aa61f95d 100644 --- a/os/gcmd/gcmd_command_run.go +++ b/os/gcmd/gcmd_command_run.go @@ -171,10 +171,12 @@ func (c *Command) reParse(ctx context.Context, parser *Parser) (*Parser, error) if arg.IsArg { continue } + optionKey = arg.Name + if arg.FieldName != "" { + optionKey += fmt.Sprintf(`,%s`, arg.FieldName) + } if arg.Short != "" { - optionKey = fmt.Sprintf(`%s,%s`, arg.Name, arg.Short) - } else { - optionKey = arg.Name + optionKey += fmt.Sprintf(`,%s`, arg.Short) } supportedOptions[optionKey] = !arg.Orphan } diff --git a/os/gcmd/gcmd_z_unit_feature_object1_test.go b/os/gcmd/gcmd_z_unit_feature_object1_test.go index a80183ce2..a2845b327 100644 --- a/os/gcmd/gcmd_z_unit_feature_object1_test.go +++ b/os/gcmd/gcmd_z_unit_feature_object1_test.go @@ -31,7 +31,7 @@ type TestCmdObjectEnvOutput struct{} type TestCmdObjectTestInput struct { g.Meta `name:"test" usage:"root test" brief:"root test command" dc:"root test command description" ad:"root test command ad"` - Name string `v:"required" short:"n" orphan:"false" brief:"name for test command"` + Name string `name:"yourname" v:"required" short:"n" orphan:"false" brief:"name for test command" d:"tom"` } type TestCmdObjectTestOutput struct { @@ -89,10 +89,23 @@ func Test_Command_NewFromObject_RunWithValue(t *testing.T) { t.AssertNil(err) t.Assert(cmd.Name, "root") + // test short name os.Args = []string{"root", "test", "-n=john"} value, err := cmd.RunWithValueError(ctx) t.AssertNil(err) t.Assert(value, `{"Content":"john"}`) + + // test name tag name + os.Args = []string{"root", "test", "-yourname=hailaz"} + value1, err1 := cmd.RunWithValueError(ctx) + t.AssertNil(err1) + t.Assert(value1, `{"Content":"hailaz"}`) + + // test default tag value + os.Args = []string{"root", "test"} + value2, err2 := cmd.RunWithValueError(ctx) + t.AssertNil(err2) + t.Assert(value2, `{"Content":"tom"}`) }) } diff --git a/util/gconv/gconv_scan.go b/util/gconv/gconv_scan.go index b31c4a3b8..6187d079d 100644 --- a/util/gconv/gconv_scan.go +++ b/util/gconv/gconv_scan.go @@ -279,7 +279,7 @@ func doScanList( relationBindToFieldName string // Eg: relationKV: id:uid -> uid ) if len(relationFields) > 0 { - // The relation key string of table filed name and attribute name + // The relation key string of table field name and attribute name // can be joined with char '=' or ':'. array := utils.SplitAndTrim(relationFields, "=") if len(array) == 1 { @@ -396,12 +396,12 @@ func doScanList( relationFromAttrField = relationFromAttrValue.FieldByName(relationBindToFieldName) if !relationFromAttrField.IsValid() { var ( - filedMap, _ = gstructs.FieldMap(gstructs.FieldMapInput{ + fieldMap, _ = gstructs.FieldMap(gstructs.FieldMapInput{ Pointer: relationFromAttrValue, RecursiveOption: gstructs.RecursiveOptionEmbeddedNoTag, }) ) - if key, _ := utils.MapPossibleItemByKey(Map(filedMap), relationBindToFieldName); key == "" { + if key, _ := utils.MapPossibleItemByKey(Map(fieldMap), relationBindToFieldName); key == "" { return gerror.NewCodef( gcode.CodeInvalidParameter, `cannot find possible related attribute name "%s" from given relation fields "%s"`, From 0bd15bdab56376ffea45976f2ed07616bf61acaa Mon Sep 17 00:00:00 2001 From: li-caspar Date: Thu, 9 Nov 2023 20:02:47 +0800 Subject: [PATCH 09/22] fix: "gf gen dao" utils.GetModPath Return empty string in windows (#3141) --- cmd/gf/internal/utility/utils/utils.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/gf/internal/utility/utils/utils.go b/cmd/gf/internal/utility/utils/utils.go index 3392e1471..bd92581f2 100644 --- a/cmd/gf/internal/utility/utils/utils.go +++ b/cmd/gf/internal/utility/utils/utils.go @@ -118,7 +118,7 @@ func GetImportPath(filePath string) string { func GetModPath() string { var ( oldDir = gfile.Pwd() - newDir = gfile.Dir(oldDir) + newDir = oldDir goModName = "go.mod" goModPath string ) @@ -127,11 +127,11 @@ func GetModPath() string { if gfile.Exists(goModPath) { return goModPath } - oldDir = newDir newDir = gfile.Dir(oldDir) if newDir == oldDir { break } + oldDir = newDir } return "" } From d4b14fd7174eda6aa7d444f3f0c7742260ad4c3d Mon Sep 17 00:00:00 2001 From: oldme <45782393+oldme-git@users.noreply.github.com> Date: Thu, 9 Nov 2023 20:04:05 +0800 Subject: [PATCH 10/22] add gen service unit testing (#3142) --- .../cmd/{cmd__test.go => cmd_z_init_test.go} | 0 ...cmd_fix_test.go => cmd_z_unit_fix_test.go} | 0 ...rl_test.go => cmd_z_unit_gen_ctrl_test.go} | 5 +- ...dao_test.go => cmd_z_unit_gen_dao_test.go} | 0 .../cmd/cmd_z_unit_gen_service_test.go | 72 +++++++++++++++++++ .../genservice/logic/article/article.go | 33 +++++++++ .../testdata/genservice/logic/logic_expect.go | 9 +++ .../testdata/genservice/service/article.go | 38 ++++++++++ 8 files changed, 154 insertions(+), 3 deletions(-) rename cmd/gf/internal/cmd/{cmd__test.go => cmd_z_init_test.go} (100%) rename cmd/gf/internal/cmd/{cmd_fix_test.go => cmd_z_unit_fix_test.go} (100%) rename cmd/gf/internal/cmd/{cmd_gen_ctrl_test.go => cmd_z_unit_gen_ctrl_test.go} (98%) rename cmd/gf/internal/cmd/{cmd_gen_dao_test.go => cmd_z_unit_gen_dao_test.go} (100%) create mode 100644 cmd/gf/internal/cmd/cmd_z_unit_gen_service_test.go create mode 100644 cmd/gf/internal/cmd/testdata/genservice/logic/article/article.go create mode 100644 cmd/gf/internal/cmd/testdata/genservice/logic/logic_expect.go create mode 100644 cmd/gf/internal/cmd/testdata/genservice/service/article.go diff --git a/cmd/gf/internal/cmd/cmd__test.go b/cmd/gf/internal/cmd/cmd_z_init_test.go similarity index 100% rename from cmd/gf/internal/cmd/cmd__test.go rename to cmd/gf/internal/cmd/cmd_z_init_test.go diff --git a/cmd/gf/internal/cmd/cmd_fix_test.go b/cmd/gf/internal/cmd/cmd_z_unit_fix_test.go similarity index 100% rename from cmd/gf/internal/cmd/cmd_fix_test.go rename to cmd/gf/internal/cmd/cmd_z_unit_fix_test.go diff --git a/cmd/gf/internal/cmd/cmd_gen_ctrl_test.go b/cmd/gf/internal/cmd/cmd_z_unit_gen_ctrl_test.go similarity index 98% rename from cmd/gf/internal/cmd/cmd_gen_ctrl_test.go rename to cmd/gf/internal/cmd/cmd_z_unit_gen_ctrl_test.go index 03cdc284c..ca4bc06c5 100644 --- a/cmd/gf/internal/cmd/cmd_gen_ctrl_test.go +++ b/cmd/gf/internal/cmd/cmd_z_unit_gen_ctrl_test.go @@ -33,7 +33,6 @@ func Test_Gen_Ctrl_Default(t *testing.T) { } ) err := gutil.FillStructWithDefault(&in) - t.AssertNil(err) err = gfile.Mkdir(path) @@ -45,7 +44,7 @@ func Test_Gen_Ctrl_Default(t *testing.T) { panic(err) } - // apiInterface files + // apiInterface file var ( genApi = apiFolder + filepath.FromSlash("/article/article.go") genApiExpect = apiFolder + filepath.FromSlash("/article/article_expect.go") @@ -79,7 +78,7 @@ func Test_Gen_Ctrl_Default(t *testing.T) { testPath + filepath.FromSlash("/article/article_v2_create.go"), testPath + filepath.FromSlash("/article/article_v2_update.go"), } - for i, _ := range files { + for i := range files { t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i])) } }) diff --git a/cmd/gf/internal/cmd/cmd_gen_dao_test.go b/cmd/gf/internal/cmd/cmd_z_unit_gen_dao_test.go similarity index 100% rename from cmd/gf/internal/cmd/cmd_gen_dao_test.go rename to cmd/gf/internal/cmd/cmd_z_unit_gen_dao_test.go diff --git a/cmd/gf/internal/cmd/cmd_z_unit_gen_service_test.go b/cmd/gf/internal/cmd/cmd_z_unit_gen_service_test.go new file mode 100644 index 000000000..7f1f9c2fc --- /dev/null +++ b/cmd/gf/internal/cmd/cmd_z_unit_gen_service_test.go @@ -0,0 +1,72 @@ +// Copyright GoFrame gf 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 cmd + +import ( + "github.com/gogf/gf/cmd/gf/v2/internal/cmd/genservice" + "github.com/gogf/gf/v2/os/gfile" + "github.com/gogf/gf/v2/test/gtest" + "github.com/gogf/gf/v2/util/guid" + "github.com/gogf/gf/v2/util/gutil" + "path/filepath" + "testing" +) + +func Test_Gen_Service_Default(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + var ( + path = gfile.Temp(guid.S()) + dstFolder = path + filepath.FromSlash("/service") + apiFolder = gtest.DataPath("genservice", "logic") + in = genservice.CGenServiceInput{ + SrcFolder: apiFolder, + DstFolder: dstFolder, + DstFileNameCase: "Snake", + WatchFile: "", + StPattern: "", + Packages: nil, + ImportPrefix: "", + Clear: false, + } + ) + err := gutil.FillStructWithDefault(&in) + t.AssertNil(err) + + err = gfile.Mkdir(path) + t.AssertNil(err) + defer gfile.Remove(path) + + _, err = genservice.CGenService{}.Service(ctx, in) + if err != nil { + panic(err) + } + + // logic file + var ( + genApi = apiFolder + filepath.FromSlash("/logic.go") + genApiExpect = apiFolder + filepath.FromSlash("/logic_expect.go") + ) + defer gfile.Remove(genApi) + t.Assert(gfile.GetContents(genApi), gfile.GetContents(genApiExpect)) + + // files + files, err := gfile.ScanDir(dstFolder, "*.go", true) + t.AssertNil(err) + t.Assert(files, []string{ + dstFolder + filepath.FromSlash("/article.go"), + }) + + // contents + testPath := gtest.DataPath("genservice", "service") + expectFiles := []string{ + testPath + filepath.FromSlash("/article.go"), + } + for i := range files { + t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i])) + } + }) +} diff --git a/cmd/gf/internal/cmd/testdata/genservice/logic/article/article.go b/cmd/gf/internal/cmd/testdata/genservice/logic/article/article.go new file mode 100644 index 000000000..01d889a25 --- /dev/null +++ b/cmd/gf/internal/cmd/testdata/genservice/logic/article/article.go @@ -0,0 +1,33 @@ +// 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 article + +import ( + "context" + "github.com/gogf/gf/cmd/gf/v2/internal/cmd/testdata/genservice/service" +) + +type sArticle struct { +} + +func init() { + service.RegisterArticle(&sArticle{}) +} + +// Get article details +func (s *sArticle) Get(ctx context.Context, id uint) (info struct{}, err error) { + return struct{}{}, err +} + +// Create +/** + * create an article. + * @author oldme + */ +func (s *sArticle) Create(ctx context.Context, info struct{}) (id uint, err error) { + return id, err +} diff --git a/cmd/gf/internal/cmd/testdata/genservice/logic/logic_expect.go b/cmd/gf/internal/cmd/testdata/genservice/logic/logic_expect.go new file mode 100644 index 000000000..c7c3f52e9 --- /dev/null +++ b/cmd/gf/internal/cmd/testdata/genservice/logic/logic_expect.go @@ -0,0 +1,9 @@ +// ========================================================================== +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ========================================================================== + +package logic + +import ( + _ "github.com/gogf/gf/cmd/gf/v2/internal/cmd/testdata/genservice/logic/article" +) diff --git a/cmd/gf/internal/cmd/testdata/genservice/service/article.go b/cmd/gf/internal/cmd/testdata/genservice/service/article.go new file mode 100644 index 000000000..765a1c8a5 --- /dev/null +++ b/cmd/gf/internal/cmd/testdata/genservice/service/article.go @@ -0,0 +1,38 @@ +// ================================================================================ +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// You can delete these comments if you wish manually maintain this interface file. +// ================================================================================ + +package service + +import ( + "context" +) + +type ( + IArticle interface { + // Get article details + Get(ctx context.Context, id uint) (info struct{}, err error) + // Create + /** + * create an article. + * @author oldme + */ + Create(ctx context.Context, info struct{}) (id uint, err error) + } +) + +var ( + localArticle IArticle +) + +func Article() IArticle { + if localArticle == nil { + panic("implement not found for interface IArticle, forgot register?") + } + return localArticle +} + +func RegisterArticle(i IArticle) { + localArticle = i +} From 4d7f9552fee9c9fa59726e14a237a69244685107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=B7=E4=BA=AE?= <739476267@qq.com> Date: Mon, 13 Nov 2023 22:05:53 +0800 Subject: [PATCH 11/22] fix: gdb unsupport aliyun hologres link (#3150) --- database/gdb/gdb.go | 2 +- database/gdb/gdb_z_mysql_internal_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/database/gdb/gdb.go b/database/gdb/gdb.go index c2c50144a..1c3344149 100644 --- a/database/gdb/gdb.go +++ b/database/gdb/gdb.go @@ -378,7 +378,7 @@ const ( ctxKeyInternalProducedSQL gctx.StrKey = `CtxKeyInternalProducedSQL` // type:[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...¶mN=valueN] - linkPattern = `(\w+):([\w\-]*):(.*?)@(\w+?)\((.+?)\)/{0,1}([^\?]*)\?{0,1}(.*)` + linkPattern = `(\w+):([\w\-\$]*):(.*?)@(\w+?)\((.+?)\)/{0,1}([^\?]*)\?{0,1}(.*)` ) type queryType int diff --git a/database/gdb/gdb_z_mysql_internal_test.go b/database/gdb/gdb_z_mysql_internal_test.go index d29589626..538ab967d 100644 --- a/database/gdb/gdb_z_mysql_internal_test.go +++ b/database/gdb/gdb_z_mysql_internal_test.go @@ -222,6 +222,22 @@ func Test_parseConfigNodeLink_WithType(t *testing.T) { t.Assert(newNode.Charset, defaultCharset) t.Assert(newNode.Protocol, `file`) }) + // #3146 + gtest.C(t, func(t *gtest.T) { + node := &ConfigNode{ + Link: `pgsql:BASIC$xxxx:123456@tcp(xxxx.hologres.aliyuncs.com:80)/xxx`, + } + newNode := parseConfigNodeLink(node) + t.Assert(newNode.Type, `pgsql`) + t.Assert(newNode.User, `BASIC$xxxx`) + t.Assert(newNode.Pass, `123456`) + t.Assert(newNode.Host, `xxxx.hologres.aliyuncs.com`) + t.Assert(newNode.Port, `80`) + t.Assert(newNode.Name, `xxx`) + t.Assert(newNode.Extra, ``) + t.Assert(newNode.Charset, defaultCharset) + t.Assert(newNode.Protocol, `tcp`) + }) } func Test_Func_doQuoteWord(t *testing.T) { From 84ed66018e9434536604a25bec3dc99f5d173f7c Mon Sep 17 00:00:00 2001 From: zhangyuyu <1580074674@qq.com> Date: Tue, 14 Nov 2023 20:00:26 +0800 Subject: [PATCH 12/22] fix issue: Windows Platform did not handle process signal (#3154) --- net/ghttp/ghttp_server_admin_windows.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/net/ghttp/ghttp_server_admin_windows.go b/net/ghttp/ghttp_server_admin_windows.go index 135dc56d5..7d83e3e0d 100644 --- a/net/ghttp/ghttp_server_admin_windows.go +++ b/net/ghttp/ghttp_server_admin_windows.go @@ -9,7 +9,19 @@ package ghttp -// registerSignalHandler does nothing on window platform. -func handleProcessSignal() { +import ( + "context" + "os" + "github.com/gogf/gf/v2/os/gproc" +) + +// handleProcessSignal handles all signals from system in blocking way. +func handleProcessSignal() { + var ctx = context.TODO() + gproc.AddSigHandlerShutdown(func(sig os.Signal) { + shutdownWebServersGracefully(ctx, sig) + }) + + gproc.Listen() } From 5580ac9475ae34fe6fbc3637634a7f6ce67768c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=B7=E4=BA=AE?= <739476267@qq.com> Date: Tue, 14 Nov 2023 20:10:49 +0800 Subject: [PATCH 13/22] fix issue in cross-building failed in windows (#3152) --- cmd/gf/internal/cmd/cmd_build.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/gf/internal/cmd/cmd_build.go b/cmd/gf/internal/cmd/cmd_build.go index 49e80a271..2a0564026 100644 --- a/cmd/gf/internal/cmd/cmd_build.go +++ b/cmd/gf/internal/cmd/cmd_build.go @@ -289,10 +289,11 @@ func (c cBuild) Index(ctx context.Context, in cBuildInput) (out *cBuildOutput, e ) } cmd = fmt.Sprintf( - `GOOS=%s GOARCH=%s go build %s -ldflags "%s" %s%s`, - system, arch, outputPath, ldFlags, in.Extra, file, + `go build %s -ldflags "%s" %s%s`, + outputPath, ldFlags, in.Extra, file, ) } + mlog.Debug(fmt.Sprintf("build for GOOS=%s GOARCH=%s", system, arch)) mlog.Debug(cmd) // It's not necessary printing the complete command string. cmdShow, _ := gregex.ReplaceString(`\s+(-ldflags ".+?")\s+`, " ", cmd) From 0be8b29e42b0c4cd01dd933858d023c8d3a12d08 Mon Sep 17 00:00:00 2001 From: oldme <45782393+oldme-git@users.noreply.github.com> Date: Tue, 14 Nov 2023 20:53:41 +0800 Subject: [PATCH 14/22] improve gen service code (#3140) --- cmd/gf/internal/cmd/genservice/genservice.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/gf/internal/cmd/genservice/genservice.go b/cmd/gf/internal/cmd/genservice/genservice.go index ceb783a84..e1ef5dc74 100644 --- a/cmd/gf/internal/cmd/genservice/genservice.go +++ b/cmd/gf/internal/cmd/genservice/genservice.go @@ -9,6 +9,7 @@ package genservice import ( "context" "fmt" + "path/filepath" "github.com/gogf/gf/v2/container/garray" "github.com/gogf/gf/v2/container/gmap" @@ -93,10 +94,10 @@ const ( ) func (c CGenService) Service(ctx context.Context, in CGenServiceInput) (out *CGenServiceOutput, err error) { - in.SrcFolder = gstr.TrimRight(in.SrcFolder, `\/`) - in.SrcFolder = gstr.Replace(in.SrcFolder, "\\", "/") - in.WatchFile = gstr.TrimRight(in.WatchFile, `\/`) - in.WatchFile = gstr.Replace(in.WatchFile, "\\", "/") + in.SrcFolder = filepath.ToSlash(in.SrcFolder) + in.SrcFolder = gstr.TrimRight(in.SrcFolder, `/`) + in.WatchFile = filepath.ToSlash(in.WatchFile) + in.WatchFile = gstr.TrimRight(in.WatchFile, `/`) // Watch file handling. if in.WatchFile != "" { From 9694a682114146471d1d8a5ae72445fbc71561fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=B7=E4=BA=AE?= <739476267@qq.com> Date: Thu, 16 Nov 2023 20:10:45 +0800 Subject: [PATCH 15/22] Optimize the information display of gf -v (#3145) --- cmd/gf/internal/cmd/cmd_version.go | 109 +++++++++++++++++++++++------ 1 file changed, 87 insertions(+), 22 deletions(-) diff --git a/cmd/gf/internal/cmd/cmd_version.go b/cmd/gf/internal/cmd/cmd_version.go index 10a31eacf..89e753cce 100644 --- a/cmd/gf/internal/cmd/cmd_version.go +++ b/cmd/gf/internal/cmd/cmd_version.go @@ -7,14 +7,19 @@ package cmd import ( + "bytes" "context" "fmt" + "runtime" + "strings" + "time" "github.com/gogf/gf/v2" "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gbuild" "github.com/gogf/gf/v2/os/gfile" + "github.com/gogf/gf/v2/os/gproc" "github.com/gogf/gf/v2/text/gregex" "github.com/gogf/gf/v2/text/gstr" @@ -25,6 +30,10 @@ var ( Version = cVersion{} ) +const ( + defaultIndent = "{{indent}}" +) + type cVersion struct { g.Meta `name:"version" brief:"show version information of current binary"` } @@ -36,34 +45,90 @@ type cVersionInput struct { type cVersionOutput struct{} func (c cVersion) Index(ctx context.Context, in cVersionInput) (*cVersionOutput, error) { - info := gbuild.Info() - if info.Git == "" { - info.Git = "none" - } - mlog.Printf(`GoFrame CLI Tool %s, https://goframe.org`, gf.VERSION) - gfVersion, err := c.getGFVersionOfCurrentProject() - if err != nil { - gfVersion = err.Error() + detailBuffer := &detailBuffer{} + detailBuffer.WriteString(fmt.Sprintf("%s", gf.VERSION)) + + detailBuffer.appendLine(0, "Welcome to GoFrame!") + + detailBuffer.appendLine(0, "Env Detail:") + goVersion, ok := getGoVersion() + if ok { + detailBuffer.appendLine(1, fmt.Sprintf("Go Version: %s", goVersion)) + detailBuffer.appendLine(1, fmt.Sprintf("GF Version(go.mod): %s", getGoFrameVersion(2))) } else { - gfVersion = gfVersion + " in current go.mod" - } - mlog.Printf(`GoFrame Version: %s`, gfVersion) - mlog.Printf(`CLI Installed At: %s`, gfile.SelfPath()) - if info.GoFrame == "" { - mlog.Print(`Current is a custom installed version, no installation information.`) - return nil, nil + v, err := c.getGFVersionOfCurrentProject() + if err == nil { + detailBuffer.appendLine(1, fmt.Sprintf("GF Version(go.mod): %s", v)) + } else { + detailBuffer.appendLine(1, fmt.Sprintf("GF Version(go.mod): %s", err.Error())) + } } - mlog.Print(gstr.Trim(fmt.Sprintf(` -CLI Built Detail: - Go Version: %s - GF Version: %s - Git Commit: %s - Build Time: %s -`, info.Golang, info.GoFrame, info.Git, info.Time))) + detailBuffer.appendLine(0, "CLI Detail:") + detailBuffer.appendLine(1, fmt.Sprintf("Installed At: %s", gfile.SelfPath())) + info := gbuild.Info() + if info.GoFrame == "" { + detailBuffer.appendLine(1, fmt.Sprintf("Built Go Version: %s", runtime.Version())) + detailBuffer.appendLine(1, fmt.Sprintf("Built GF Version: %s", gf.VERSION)) + } else { + if info.Git == "" { + info.Git = "none" + } + detailBuffer.appendLine(1, fmt.Sprintf("Built Go Version: %s", info.Golang)) + detailBuffer.appendLine(1, fmt.Sprintf("Built GF Version: %s", info.GoFrame)) + detailBuffer.appendLine(1, fmt.Sprintf("Git Commit: %s", info.Git)) + detailBuffer.appendLine(1, fmt.Sprintf("Built Time: %s", info.Time)) + } + + detailBuffer.appendLine(0, "Others Detail:") + detailBuffer.appendLine(1, "Docs: https://goframe.org") + detailBuffer.appendLine(1, fmt.Sprintf("Now : %s", time.Now().Format(time.RFC3339))) + + mlog.Print(detailBuffer.replaceAllIndent(" ")) return nil, nil } +// detailBuffer is a buffer for detail information. +type detailBuffer struct { + bytes.Buffer +} + +// appendLine appends a line to the buffer with given indent level. +func (d *detailBuffer) appendLine(indentLevel int, line string) { + d.WriteString(fmt.Sprintf("\n%s%s", strings.Repeat(defaultIndent, indentLevel), line)) +} + +// replaceAllIndent replaces the tab with given indent string and prints the buffer content. +func (d *detailBuffer) replaceAllIndent(indentStr string) string { + return strings.ReplaceAll(d.String(), defaultIndent, indentStr) +} + +// getGoFrameVersion returns the goframe version of current project using. +func getGoFrameVersion(indentLevel int) (gfVersion string) { + pkgInfo, err := gproc.ShellExec(context.Background(), `go list -f "{{if (not .Main)}}{{.Path}}@{{.Version}}{{end}}" -m all`) + if err != nil { + return "cannot find go.mod" + } + pkgList := gstr.Split(pkgInfo, "\n") + for _, v := range pkgList { + if strings.HasPrefix(v, "github.com/gogf/gf") { + gfVersion += fmt.Sprintf("\n%s%s", strings.Repeat(defaultIndent, indentLevel), v) + } + } + return +} + +// getGoVersion returns the go version +func getGoVersion() (goVersion string, ok bool) { + goVersion, err := gproc.ShellExec(context.Background(), "go version") + if err != nil { + return "", false + } + goVersion = gstr.TrimLeftStr(goVersion, "go version ") + goVersion = gstr.TrimRightStr(goVersion, "\n") + return goVersion, true +} + // getGFVersionOfCurrentProject checks and returns the GoFrame version current project using. func (c cVersion) getGFVersionOfCurrentProject() (string, error) { goModPath := gfile.Join(gfile.Pwd(), "go.mod") From 85acd3d31d764a6e7c9f0d08749839b3805d3bfa Mon Sep 17 00:00:00 2001 From: wlqe Date: Thu, 16 Nov 2023 20:15:48 +0800 Subject: [PATCH 16/22] Fix the bug that ScanAndCount and AllAndCount report errors in sqlserver (#3155) --- contrib/drivers/mssql/mssql_z_model_test.go | 37 +++++++++++++++++++++ database/gdb/gdb_model_select.go | 6 ++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/contrib/drivers/mssql/mssql_z_model_test.go b/contrib/drivers/mssql/mssql_z_model_test.go index 4e1550684..2310493a3 100644 --- a/contrib/drivers/mssql/mssql_z_model_test.go +++ b/contrib/drivers/mssql/mssql_z_model_test.go @@ -2548,3 +2548,40 @@ func Test_Model_WherePrefixLike(t *testing.T) { t.Assert(r[0]["ID"], "3") }) } + +func Test_Model_AllAndCount(t *testing.T) { + table := createInitTable() + defer dropTable(table) + + gtest.C(t, func(t *gtest.T) { + result, total, err := db.Model(table).Order("id").Limit(0, 3).AllAndCount(false) + t.Assert(err, nil) + + t.Assert(len(result), 3) + t.Assert(total, TableSize) + }) +} + +func Test_Model_ScanAndCount(t *testing.T) { + table := createInitTable() + defer dropTable(table) + + gtest.C(t, func(t *gtest.T) { + type User struct { + Id int + Passport string + Password string + NickName string + CreateTime gtime.Time + } + + users := make([]User, 0) + total := 0 + + err := db.Model(table).Order("id").Limit(0, 3).ScanAndCount(&users, &total, false) + t.Assert(err, nil) + + t.Assert(len(users), 3) + t.Assert(total, TableSize) + }) +} diff --git a/database/gdb/gdb_model_select.go b/database/gdb/gdb_model_select.go index de19b8d62..5a37968f7 100644 --- a/database/gdb/gdb_model_select.go +++ b/database/gdb/gdb_model_select.go @@ -768,8 +768,10 @@ func (m *Model) formatCondition( } } // ORDER BY. - if m.orderBy != "" { - conditionExtra += " ORDER BY " + m.orderBy + if !isCountStatement { // The count statement of sqlserver cannot contain the order by statement + if m.orderBy != "" { + conditionExtra += " ORDER BY " + m.orderBy + } } // LIMIT. if !isCountStatement { From fc8572e8dd3532f754b2140559dd21338f118e0a Mon Sep 17 00:00:00 2001 From: John Guo Date: Mon, 20 Nov 2023 10:01:54 +0800 Subject: [PATCH 17/22] version v2.5.7 (#3162) --- cmd/gf/go.mod | 18 +++++++++--------- cmd/gf/go.sum | 9 ++++----- contrib/config/apollo/go.mod | 2 +- contrib/config/consul/go.mod | 2 +- contrib/config/kubecm/go.mod | 6 +++--- contrib/config/kubecm/go.sum | 9 ++++----- contrib/config/nacos/go.mod | 2 +- contrib/config/polaris/go.mod | 2 +- contrib/drivers/clickhouse/go.mod | 6 +++--- contrib/drivers/clickhouse/go.sum | 9 ++++----- contrib/drivers/dm/go.mod | 6 +++--- contrib/drivers/dm/go.sum | 13 ++++++------- contrib/drivers/mssql/go.mod | 6 +++--- contrib/drivers/mssql/go.sum | 9 ++++----- contrib/drivers/mysql/go.mod | 6 +++--- contrib/drivers/mysql/go.sum | 9 ++++----- contrib/drivers/oracle/go.mod | 6 +++--- contrib/drivers/oracle/go.sum | 9 ++++----- contrib/drivers/pgsql/go.mod | 6 +++--- contrib/drivers/pgsql/go.sum | 9 ++++----- contrib/drivers/sqlite/go.mod | 6 +++--- contrib/drivers/sqlite/go.sum | 9 ++++----- contrib/drivers/sqlitecgo/go.mod | 6 +++--- contrib/drivers/sqlitecgo/go.sum | 9 ++++----- contrib/nosql/redis/go.mod | 2 +- contrib/registry/etcd/go.mod | 2 +- contrib/registry/file/go.mod | 2 +- contrib/registry/nacos/go.mod | 2 +- contrib/registry/polaris/go.mod | 2 +- contrib/registry/zookeeper/go.mod | 2 +- contrib/rpc/grpcx/go.mod | 4 ++-- contrib/sdk/httpclient/go.mod | 6 +++--- contrib/sdk/httpclient/go.sum | 9 ++++----- contrib/trace/jaeger/go.mod | 2 +- contrib/trace/jaeger/go.sum | 4 ++-- contrib/trace/otlpgrpc/go.mod | 15 ++++++++++++++- contrib/trace/otlpgrpc/go.sum | 23 +++++++++++++++++++++++ contrib/trace/otlphttp/go.mod | 15 ++++++++++++++- contrib/trace/otlphttp/go.sum | 23 +++++++++++++++++++++++ example/go.mod | 28 ++++++++++++++-------------- version.go | 2 +- 41 files changed, 189 insertions(+), 128 deletions(-) diff --git a/cmd/gf/go.mod b/cmd/gf/go.mod index 96bce9a1f..48579f385 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.6 - github.com/gogf/gf/contrib/drivers/mssql/v2 v2.5.6 - github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.6 - github.com/gogf/gf/contrib/drivers/oracle/v2 v2.5.6 - github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.5.6 - github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.5.6 - github.com/gogf/gf/v2 v2.5.6 + github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.5.7 + github.com/gogf/gf/contrib/drivers/mssql/v2 v2.5.7 + github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.7 + github.com/gogf/gf/contrib/drivers/oracle/v2 v2.5.7 + github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.5.7 + github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.5.7 + github.com/gogf/gf/v2 v2.5.7 github.com/minio/selfupdate v0.6.0 github.com/olekukonko/tablewriter v0.0.5 golang.org/x/mod v0.9.0 @@ -24,7 +24,7 @@ require ( github.com/denisenkom/go-mssqldb v0.12.3 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/fatih/color v1.15.0 // indirect - github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/glebarez/go-sqlite v1.21.2 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect @@ -37,7 +37,7 @@ require ( github.com/lib/pq v1.10.9 // indirect github.com/magiconair/properties v1.8.6 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/paulmach/orb v0.7.1 // indirect github.com/pierrec/lz4/v4 v4.1.14 // indirect diff --git a/cmd/gf/go.sum b/cmd/gf/go.sum index a97c48290..bb5f8a4a8 100644 --- a/cmd/gf/go.sum +++ b/cmd/gf/go.sum @@ -23,8 +23,8 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= -github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= -github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo= github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -67,8 +67,8 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -159,7 +159,6 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/contrib/config/apollo/go.mod b/contrib/config/apollo/go.mod index da2f27059..660c47820 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.3.1 - github.com/gogf/gf/v2 v2.5.6 + github.com/gogf/gf/v2 v2.5.7 ) require ( diff --git a/contrib/config/consul/go.mod b/contrib/config/consul/go.mod index bf072933d..bf1c2fcb4 100644 --- a/contrib/config/consul/go.mod +++ b/contrib/config/consul/go.mod @@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/consul/v2 go 1.19 require ( - github.com/gogf/gf/v2 v2.5.6 + github.com/gogf/gf/v2 v2.5.7 github.com/hashicorp/consul/api v1.24.0 github.com/hashicorp/go-cleanhttp v0.5.2 ) diff --git a/contrib/config/kubecm/go.mod b/contrib/config/kubecm/go.mod index 448dc155b..3f9770b1b 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.6 + github.com/gogf/gf/v2 v2.5.7 k8s.io/api v0.27.4 k8s.io/apimachinery v0.27.4 k8s.io/client-go v0.27.4 @@ -15,7 +15,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/emicklei/go-restful/v3 v3.9.0 // indirect github.com/fatih/color v1.15.0 // indirect - github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect @@ -35,7 +35,7 @@ require ( github.com/magiconair/properties v1.8.6 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect diff --git a/contrib/config/kubecm/go.sum b/contrib/config/kubecm/go.sum index d09797a70..dfcb587c5 100644 --- a/contrib/config/kubecm/go.sum +++ b/contrib/config/kubecm/go.sum @@ -56,8 +56,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= -github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= -github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -168,8 +168,8 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -330,7 +330,6 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/contrib/config/nacos/go.mod b/contrib/config/nacos/go.mod index 2f510f538..48b6c46f4 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.6 + github.com/gogf/gf/v2 v2.5.7 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 9ef83bb8a..51ae7e0c9 100644 --- a/contrib/config/polaris/go.mod +++ b/contrib/config/polaris/go.mod @@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/polaris/v2 go 1.18 require ( - github.com/gogf/gf/v2 v2.5.6 + github.com/gogf/gf/v2 v2.5.7 github.com/polarismesh/polaris-go v1.5.5 ) diff --git a/contrib/drivers/clickhouse/go.mod b/contrib/drivers/clickhouse/go.mod index 24fbd02e4..b9a902dbd 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.6 + github.com/gogf/gf/v2 v2.5.7 github.com/google/uuid v1.3.0 github.com/shopspring/decimal v1.3.1 ) @@ -13,14 +13,14 @@ require ( github.com/BurntSushi/toml v1.2.0 // indirect github.com/clbanning/mxj/v2 v2.7.0 // indirect github.com/fatih/color v1.15.0 // indirect - github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grokify/html-strip-tags-go v0.0.1 // indirect github.com/magiconair/properties v1.8.6 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/paulmach/orb v0.7.1 // indirect diff --git a/contrib/drivers/clickhouse/go.sum b/contrib/drivers/clickhouse/go.sum index d951a1ceb..a20052e83 100644 --- a/contrib/drivers/clickhouse/go.sum +++ b/contrib/drivers/clickhouse/go.sum @@ -10,8 +10,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= -github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= -github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= @@ -45,8 +45,8 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -111,7 +111,6 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/contrib/drivers/dm/go.mod b/contrib/drivers/dm/go.mod index 510e0c6bd..2f187647a 100644 --- a/contrib/drivers/dm/go.mod +++ b/contrib/drivers/dm/go.mod @@ -6,14 +6,14 @@ replace github.com/gogf/gf/v2 => ../../../ require ( gitee.com/chunanyong/dm v1.8.12 - github.com/gogf/gf/v2 v2.5.6 + github.com/gogf/gf/v2 v2.5.7 ) require ( github.com/BurntSushi/toml v1.2.0 // indirect github.com/clbanning/mxj/v2 v2.7.0 // indirect github.com/fatih/color v1.15.0 // indirect - github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/golang/snappy v0.0.1 // indirect @@ -21,7 +21,7 @@ require ( github.com/grokify/html-strip-tags-go v0.0.1 // indirect github.com/magiconair/properties v1.8.6 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/rivo/uniseg v0.4.4 // indirect diff --git a/contrib/drivers/dm/go.sum b/contrib/drivers/dm/go.sum index 314d41db4..eb74f6ab3 100644 --- a/contrib/drivers/dm/go.sum +++ b/contrib/drivers/dm/go.sum @@ -1,5 +1,5 @@ -gitee.com/chunanyong/dm v1.8.10 h1:9S1CKUggWHIea/GI7nr7S/DNMaxIilNFgfzdzKDx2+I= -gitee.com/chunanyong/dm v1.8.10/go.mod h1:EPRJnuPFgbyOFgJ0TRYCTGzhq+ZT4wdyaj/GW/LLcNg= +gitee.com/chunanyong/dm v1.8.12 h1:WupbFZL0MRNIIiCPaLDHgFi5jkdkjzjPReuWPaInGwk= +gitee.com/chunanyong/dm v1.8.12/go.mod h1:EPRJnuPFgbyOFgJ0TRYCTGzhq+ZT4wdyaj/GW/LLcNg= github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME= @@ -7,8 +7,8 @@ github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= -github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= -github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -26,8 +26,8 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -47,7 +47,6 @@ go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+go golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/contrib/drivers/mssql/go.mod b/contrib/drivers/mssql/go.mod index 571f9bda3..24b42a513 100644 --- a/contrib/drivers/mssql/go.mod +++ b/contrib/drivers/mssql/go.mod @@ -4,14 +4,14 @@ go 1.18 require ( github.com/denisenkom/go-mssqldb v0.12.3 - github.com/gogf/gf/v2 v2.5.6 + github.com/gogf/gf/v2 v2.5.7 ) require ( github.com/BurntSushi/toml v1.2.0 // indirect github.com/clbanning/mxj/v2 v2.7.0 // indirect github.com/fatih/color v1.15.0 // indirect - github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect @@ -20,7 +20,7 @@ require ( github.com/grokify/html-strip-tags-go v0.0.1 // indirect github.com/magiconair/properties v1.8.6 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/rivo/uniseg v0.4.4 // indirect diff --git a/contrib/drivers/mssql/go.sum b/contrib/drivers/mssql/go.sum index cb9da0016..1c24aa099 100644 --- a/contrib/drivers/mssql/go.sum +++ b/contrib/drivers/mssql/go.sum @@ -13,8 +13,8 @@ github.com/denisenkom/go-mssqldb v0.12.3/go.mod h1:k0mtMFOnU+AihqFxPMiF05rtiDror github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= -github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= -github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -34,8 +34,8 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -73,7 +73,6 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/contrib/drivers/mysql/go.mod b/contrib/drivers/mysql/go.mod index 31596e88d..21db76fdd 100644 --- a/contrib/drivers/mysql/go.mod +++ b/contrib/drivers/mysql/go.mod @@ -4,21 +4,21 @@ go 1.18 require ( github.com/go-sql-driver/mysql v1.7.1 - github.com/gogf/gf/v2 v2.5.6 + github.com/gogf/gf/v2 v2.5.7 ) require ( github.com/BurntSushi/toml v1.2.0 // indirect github.com/clbanning/mxj/v2 v2.7.0 // indirect github.com/fatih/color v1.15.0 // indirect - github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grokify/html-strip-tags-go v0.0.1 // indirect github.com/magiconair/properties v1.8.6 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/rivo/uniseg v0.4.4 // indirect diff --git a/contrib/drivers/mysql/go.sum b/contrib/drivers/mysql/go.sum index b21c5d6bc..ee6480831 100644 --- a/contrib/drivers/mysql/go.sum +++ b/contrib/drivers/mysql/go.sum @@ -5,8 +5,8 @@ github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= -github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= -github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -24,8 +24,8 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -45,7 +45,6 @@ go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+go golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/contrib/drivers/oracle/go.mod b/contrib/drivers/oracle/go.mod index cdacdf79a..d71523e10 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.6 + github.com/gogf/gf/v2 v2.5.7 github.com/sijms/go-ora/v2 v2.7.10 ) @@ -11,14 +11,14 @@ require ( github.com/BurntSushi/toml v1.2.0 // indirect github.com/clbanning/mxj/v2 v2.7.0 // indirect github.com/fatih/color v1.15.0 // indirect - github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grokify/html-strip-tags-go v0.0.1 // indirect github.com/magiconair/properties v1.8.6 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/rivo/uniseg v0.4.4 // indirect diff --git a/contrib/drivers/oracle/go.sum b/contrib/drivers/oracle/go.sum index 7aed5e437..2ecb86713 100644 --- a/contrib/drivers/oracle/go.sum +++ b/contrib/drivers/oracle/go.sum @@ -5,8 +5,8 @@ github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= -github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= -github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -22,8 +22,8 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -45,7 +45,6 @@ go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+go golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/contrib/drivers/pgsql/go.mod b/contrib/drivers/pgsql/go.mod index f2700127e..5da1ae1ef 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.6 + github.com/gogf/gf/v2 v2.5.7 github.com/lib/pq v1.10.9 ) @@ -11,14 +11,14 @@ require ( github.com/BurntSushi/toml v1.2.0 // indirect github.com/clbanning/mxj/v2 v2.7.0 // indirect github.com/fatih/color v1.15.0 // indirect - github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grokify/html-strip-tags-go v0.0.1 // indirect github.com/magiconair/properties v1.8.6 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/rivo/uniseg v0.4.4 // indirect diff --git a/contrib/drivers/pgsql/go.sum b/contrib/drivers/pgsql/go.sum index fb5e6b771..07e965358 100644 --- a/contrib/drivers/pgsql/go.sum +++ b/contrib/drivers/pgsql/go.sum @@ -5,8 +5,8 @@ github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= -github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= -github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -24,8 +24,8 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -45,7 +45,6 @@ go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+go golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/contrib/drivers/sqlite/go.mod b/contrib/drivers/sqlite/go.mod index 2d2460503..acf2067b5 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.6 + github.com/gogf/gf/v2 v2.5.7 ) require ( @@ -12,7 +12,7 @@ require ( github.com/clbanning/mxj/v2 v2.7.0 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/fatih/color v1.15.0 // indirect - github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/google/uuid v1.3.0 // indirect @@ -20,7 +20,7 @@ require ( github.com/grokify/html-strip-tags-go v0.0.1 // indirect github.com/magiconair/properties v1.8.6 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect diff --git a/contrib/drivers/sqlite/go.sum b/contrib/drivers/sqlite/go.sum index 6813208d6..ba3cbf041 100644 --- a/contrib/drivers/sqlite/go.sum +++ b/contrib/drivers/sqlite/go.sum @@ -7,8 +7,8 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= -github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= -github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo= github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -29,8 +29,8 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -53,7 +53,6 @@ go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+go golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/contrib/drivers/sqlitecgo/go.mod b/contrib/drivers/sqlitecgo/go.mod index cfc29f353..ee53a450d 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.6 + github.com/gogf/gf/v2 v2.5.7 github.com/mattn/go-sqlite3 v1.14.17 ) @@ -11,14 +11,14 @@ require ( github.com/BurntSushi/toml v1.2.0 // indirect github.com/clbanning/mxj/v2 v2.7.0 // indirect github.com/fatih/color v1.15.0 // indirect - github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grokify/html-strip-tags-go v0.0.1 // indirect github.com/magiconair/properties v1.8.6 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/rivo/uniseg v0.4.4 // indirect diff --git a/contrib/drivers/sqlitecgo/go.sum b/contrib/drivers/sqlitecgo/go.sum index 785f16d6c..22f425241 100644 --- a/contrib/drivers/sqlitecgo/go.sum +++ b/contrib/drivers/sqlitecgo/go.sum @@ -5,8 +5,8 @@ github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= -github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= -github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -22,8 +22,8 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -45,7 +45,6 @@ go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+go golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/contrib/nosql/redis/go.mod b/contrib/nosql/redis/go.mod index e7f4657fd..0284ad9f7 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.6 + github.com/gogf/gf/v2 v2.5.7 github.com/redis/go-redis/v9 v9.2.1 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 141a792a7..159a9c210 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.6 + github.com/gogf/gf/v2 v2.5.7 go.etcd.io/etcd/client/v3 v3.5.7 ) diff --git a/contrib/registry/file/go.mod b/contrib/registry/file/go.mod index ff8f0f3c4..83b0ca1c5 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.6 +require github.com/gogf/gf/v2 v2.5.7 require ( github.com/BurntSushi/toml v1.2.0 // indirect diff --git a/contrib/registry/nacos/go.mod b/contrib/registry/nacos/go.mod index 73535a600..d8830683e 100644 --- a/contrib/registry/nacos/go.mod +++ b/contrib/registry/nacos/go.mod @@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/registry/nacos/v2 go 1.18 require ( - github.com/gogf/gf/v2 v2.5.6 + github.com/gogf/gf/v2 v2.5.7 github.com/joy999/nacos-sdk-go v0.0.0-20231008093845-7f2f84bc6faa ) diff --git a/contrib/registry/polaris/go.mod b/contrib/registry/polaris/go.mod index 568dbaad5..92c0663d2 100644 --- a/contrib/registry/polaris/go.mod +++ b/contrib/registry/polaris/go.mod @@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/registry/polaris/v2 go 1.18 require ( - github.com/gogf/gf/v2 v2.5.6 + github.com/gogf/gf/v2 v2.5.7 github.com/polarismesh/polaris-go v1.5.5 ) diff --git a/contrib/registry/zookeeper/go.mod b/contrib/registry/zookeeper/go.mod index 780544112..61ebd46a1 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.6 + github.com/gogf/gf/v2 v2.5.7 golang.org/x/sync v0.4.0 ) diff --git a/contrib/rpc/grpcx/go.mod b/contrib/rpc/grpcx/go.mod index f287c8b08..eb893110e 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.6 - github.com/gogf/gf/v2 v2.5.6 + github.com/gogf/gf/contrib/registry/file/v2 v2.5.7 + github.com/gogf/gf/v2 v2.5.7 go.opentelemetry.io/otel v1.14.0 go.opentelemetry.io/otel/trace v1.14.0 google.golang.org/grpc v1.57.2 diff --git a/contrib/sdk/httpclient/go.mod b/contrib/sdk/httpclient/go.mod index 091aaa9b8..f848861ae 100644 --- a/contrib/sdk/httpclient/go.mod +++ b/contrib/sdk/httpclient/go.mod @@ -2,20 +2,20 @@ module github.com/gogf/gf/contrib/sdk/httpclient/v2 go 1.18 -require github.com/gogf/gf/v2 v2.5.6 +require github.com/gogf/gf/v2 v2.5.7 require ( github.com/BurntSushi/toml v1.2.0 // indirect github.com/clbanning/mxj/v2 v2.7.0 // indirect github.com/fatih/color v1.15.0 // indirect - github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grokify/html-strip-tags-go v0.0.1 // indirect github.com/magiconair/properties v1.8.6 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/rivo/uniseg v0.4.4 // indirect diff --git a/contrib/sdk/httpclient/go.sum b/contrib/sdk/httpclient/go.sum index 5eda040b6..f083621d9 100644 --- a/contrib/sdk/httpclient/go.sum +++ b/contrib/sdk/httpclient/go.sum @@ -5,8 +5,8 @@ github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= -github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= -github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -22,8 +22,8 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -43,7 +43,6 @@ go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+go golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/contrib/trace/jaeger/go.mod b/contrib/trace/jaeger/go.mod index 15a3ae254..dd1ad15fc 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.6 + github.com/gogf/gf/v2 v2.5.7 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/jaeger/go.sum b/contrib/trace/jaeger/go.sum index 40f0d0e8d..96f073451 100644 --- a/contrib/trace/jaeger/go.sum +++ b/contrib/trace/jaeger/go.sum @@ -2,7 +2,7 @@ github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0 github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= -github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -13,7 +13,7 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/contrib/trace/otlpgrpc/go.mod b/contrib/trace/otlpgrpc/go.mod index 7b08a175c..867c1e998 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.6 + github.com/gogf/gf/v2 v2.5.7 go.opentelemetry.io/otel v1.19.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 @@ -12,11 +12,23 @@ require ( ) require ( + github.com/BurntSushi/toml v1.2.0 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect + github.com/clbanning/mxj/v2 v2.7.0 // indirect + github.com/fatih/color v1.15.0 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/golang/protobuf v1.5.3 // indirect + github.com/gorilla/websocket v1.5.0 // indirect + github.com/grokify/html-strip-tags-go v0.0.1 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect + github.com/magiconair/properties v1.8.6 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mattn/go-runewidth v0.0.15 // indirect + github.com/olekukonko/tablewriter v0.0.5 // indirect + github.com/rivo/uniseg v0.4.4 // indirect go.opentelemetry.io/otel/metric v1.19.0 // indirect go.opentelemetry.io/otel/trace v1.19.0 // indirect go.opentelemetry.io/proto/otlp v1.0.0 // indirect @@ -26,6 +38,7 @@ require ( google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect google.golang.org/protobuf v1.31.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) replace github.com/gogf/gf/v2 => ../../../ diff --git a/contrib/trace/otlpgrpc/go.sum b/contrib/trace/otlpgrpc/go.sum index 3c6af600b..979a8865c 100644 --- a/contrib/trace/otlpgrpc/go.sum +++ b/contrib/trace/otlpgrpc/go.sum @@ -1,10 +1,14 @@ github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= +github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME= +github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= +github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -17,16 +21,30 @@ github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0= +github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78= github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 h1:RtRsiaGvWxcwd8y3BiRZxsylPT8hLWZ5SPcfI+3IDNk= github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0/go.mod h1:TzP6duP4Py2pHLVPPQp42aoYI92+PCrVotyR5e8Vqlk= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= +github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= +github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= +github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs= go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY= @@ -45,6 +63,8 @@ go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v8 go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= @@ -61,4 +81,7 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/contrib/trace/otlphttp/go.mod b/contrib/trace/otlphttp/go.mod index 0a070227e..83d998684 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.6 + github.com/gogf/gf/v2 v2.5.7 go.opentelemetry.io/otel v1.19.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 @@ -11,11 +11,23 @@ require ( ) require ( + github.com/BurntSushi/toml v1.2.0 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect + github.com/clbanning/mxj/v2 v2.7.0 // indirect + github.com/fatih/color v1.15.0 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/golang/protobuf v1.5.3 // indirect + github.com/gorilla/websocket v1.5.0 // indirect + github.com/grokify/html-strip-tags-go v0.0.1 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect + github.com/magiconair/properties v1.8.6 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mattn/go-runewidth v0.0.15 // indirect + github.com/olekukonko/tablewriter v0.0.5 // indirect + github.com/rivo/uniseg v0.4.4 // indirect go.opentelemetry.io/otel/metric v1.19.0 // indirect go.opentelemetry.io/otel/trace v1.19.0 // indirect go.opentelemetry.io/proto/otlp v1.0.0 // indirect @@ -27,6 +39,7 @@ require ( google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect google.golang.org/grpc v1.59.0 // indirect google.golang.org/protobuf v1.31.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) replace github.com/gogf/gf/v2 => ../../../ diff --git a/contrib/trace/otlphttp/go.sum b/contrib/trace/otlphttp/go.sum index 480f17db3..98fc45252 100644 --- a/contrib/trace/otlphttp/go.sum +++ b/contrib/trace/otlphttp/go.sum @@ -1,10 +1,14 @@ github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= +github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME= +github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= +github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -17,16 +21,30 @@ github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0= +github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78= github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 h1:RtRsiaGvWxcwd8y3BiRZxsylPT8hLWZ5SPcfI+3IDNk= github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0/go.mod h1:TzP6duP4Py2pHLVPPQp42aoYI92+PCrVotyR5e8Vqlk= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= +github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= +github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= +github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs= go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY= @@ -44,6 +62,8 @@ go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lI go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= @@ -61,4 +81,7 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/example/go.mod b/example/go.mod index 5566a6616..c95a2700d 100644 --- a/example/go.mod +++ b/example/go.mod @@ -3,21 +3,21 @@ module github.com/gogf/gf/example go 1.20 require ( - github.com/gogf/gf/contrib/config/apollo/v2 v2.5.6 - github.com/gogf/gf/contrib/config/consul/v2 v2.5.6 - github.com/gogf/gf/contrib/config/kubecm/v2 v2.5.6 - github.com/gogf/gf/contrib/config/nacos/v2 v2.5.6 - github.com/gogf/gf/contrib/config/polaris/v2 v2.5.6 - github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.6 - github.com/gogf/gf/contrib/nosql/redis/v2 v2.5.6 - github.com/gogf/gf/contrib/registry/etcd/v2 v2.5.6 - github.com/gogf/gf/contrib/registry/file/v2 v2.5.6 + github.com/gogf/gf/contrib/config/apollo/v2 v2.5.7 + github.com/gogf/gf/contrib/config/consul/v2 v2.5.7 + github.com/gogf/gf/contrib/config/kubecm/v2 v2.5.7 + github.com/gogf/gf/contrib/config/nacos/v2 v2.5.7 + github.com/gogf/gf/contrib/config/polaris/v2 v2.5.7 + github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.7 + github.com/gogf/gf/contrib/nosql/redis/v2 v2.5.7 + github.com/gogf/gf/contrib/registry/etcd/v2 v2.5.7 + github.com/gogf/gf/contrib/registry/file/v2 v2.5.7 github.com/gogf/gf/contrib/registry/nacos/v2 v2.5.6 - github.com/gogf/gf/contrib/registry/polaris/v2 v2.5.6 - github.com/gogf/gf/contrib/rpc/grpcx/v2 v2.5.6 - github.com/gogf/gf/contrib/trace/otlpgrpc/v2 v2.5.6 - github.com/gogf/gf/contrib/trace/otlphttp/v2 v2.5.6 - github.com/gogf/gf/v2 v2.5.6 + github.com/gogf/gf/contrib/registry/polaris/v2 v2.5.7 + github.com/gogf/gf/contrib/rpc/grpcx/v2 v2.5.7 + github.com/gogf/gf/contrib/trace/otlpgrpc/v2 v2.5.7 + github.com/gogf/gf/contrib/trace/otlphttp/v2 v2.5.7 + github.com/gogf/gf/v2 v2.5.7 github.com/hashicorp/consul/api v1.24.0 github.com/hashicorp/go-cleanhttp v0.5.2 github.com/nacos-group/nacos-sdk-go v1.1.4 diff --git a/version.go b/version.go index 0526e4fa5..2cd4a2f6e 100644 --- a/version.go +++ b/version.go @@ -2,5 +2,5 @@ package gf const ( // VERSION is the current GoFrame version. - VERSION = "v2.5.6" + VERSION = "v2.5.7" ) From d3d1f94e403e808a239fd4367a1bce4901ce7808 Mon Sep 17 00:00:00 2001 From: Hunk Zhu Date: Mon, 20 Nov 2023 20:47:00 +0800 Subject: [PATCH 18/22] Upgrade nacos sdk to latest version (#3166) --- contrib/registry/nacos/go.mod | 10 ++++++++-- contrib/registry/nacos/go.sum | 23 +++++++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/contrib/registry/nacos/go.mod b/contrib/registry/nacos/go.mod index d8830683e..bddf9aaa5 100644 --- a/contrib/registry/nacos/go.mod +++ b/contrib/registry/nacos/go.mod @@ -4,12 +4,17 @@ go 1.18 require ( github.com/gogf/gf/v2 v2.5.7 - github.com/joy999/nacos-sdk-go v0.0.0-20231008093845-7f2f84bc6faa + github.com/joy999/nacos-sdk-go v0.0.0-20231120071639-10a34b3e7288 ) require ( github.com/BurntSushi/toml v1.2.0 // indirect - github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704 // indirect + github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 // indirect + github.com/alibabacloud-go/tea v1.1.17 // indirect + github.com/alibabacloud-go/tea-utils v1.4.4 // indirect + github.com/aliyun/alibaba-cloud-sdk-go v1.61.1800 // indirect + github.com/aliyun/alibabacloud-dkms-gcs-go-sdk v0.2.2 // indirect + github.com/aliyun/alibabacloud-dkms-transfer-go-sdk v0.1.7 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/buger/jsonparser v1.1.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect @@ -44,6 +49,7 @@ require ( go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.21.0 // indirect + golang.org/x/crypto v0.14.0 // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/sync v0.1.0 // indirect golang.org/x/sys v0.13.0 // indirect diff --git a/contrib/registry/nacos/go.sum b/contrib/registry/nacos/go.sum index bddc41df7..34d017091 100644 --- a/contrib/registry/nacos/go.sum +++ b/contrib/registry/nacos/go.sum @@ -40,8 +40,19 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= -github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704 h1:PpfENOj/vPfhhy9N2OFRjpue0hjM5XqAp2thFmkXXIk= -github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704/go.mod h1:RcDobYh8k5VP6TNybz9m++gL3ijVI5wueVr0EM10VsU= +github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 h1:NqugFkGxx1TXSh/pBcU00Y6bljgDPaFdh5MUSeJ7e50= +github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68/go.mod h1:6pb/Qy8c+lqua8cFpEy7g39NRRqOWc3rOwAy8m5Y2BY= +github.com/alibabacloud-go/tea v1.1.0/go.mod h1:IkGyUSX4Ba1V+k4pCtJUc6jDpZLFph9QMy2VUPTwukg= +github.com/alibabacloud-go/tea v1.1.17 h1:05R5DnaJXe9sCNIe8KUgWHC/z6w/VZIwczgUwzRnul8= +github.com/alibabacloud-go/tea v1.1.17/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A= +github.com/alibabacloud-go/tea-utils v1.4.4 h1:lxCDvNCdTo9FaXKKq45+4vGETQUKNOW/qKTcX9Sk53o= +github.com/alibabacloud-go/tea-utils v1.4.4/go.mod h1:KNcT0oXlZZxOXINnZBs6YvgOd5aYp9U67G+E3R8fcQw= +github.com/aliyun/alibaba-cloud-sdk-go v1.61.1800 h1:ie/8RxBOfKZWcrbYSJi2Z8uX8TcOlSMwPlEJh83OeOw= +github.com/aliyun/alibaba-cloud-sdk-go v1.61.1800/go.mod h1:RcDobYh8k5VP6TNybz9m++gL3ijVI5wueVr0EM10VsU= +github.com/aliyun/alibabacloud-dkms-gcs-go-sdk v0.2.2 h1:rWkH6D2XlXb/Y+tNAQROxBzp3a0p92ni+pXcaHBe/WI= +github.com/aliyun/alibabacloud-dkms-gcs-go-sdk v0.2.2/go.mod h1:GDtq+Kw+v0fO+j5BrrWiUHbBq7L+hfpzpPfXKOZMFE0= +github.com/aliyun/alibabacloud-dkms-transfer-go-sdk v0.1.7 h1:olLiPI2iM8Hqq6vKnSxpM3awCrm9/BeOgHpzQkOYnI4= +github.com/aliyun/alibabacloud-dkms-transfer-go-sdk v0.1.7/go.mod h1:oDg1j4kFxnhgftaiLJABkGeSvuEvSF5Lo6UmRAMruX4= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= @@ -155,8 +166,8 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= -github.com/joy999/nacos-sdk-go v0.0.0-20231008093845-7f2f84bc6faa h1:FPzhsWW/aZQKw9tWOTvLc8lpKLGnPVBMaF0B+DIvKlc= -github.com/joy999/nacos-sdk-go v0.0.0-20231008093845-7f2f84bc6faa/go.mod h1:vks3UUh7Hp+e5qbvDySGnvVCD0RYqjyDy/RpVMSf3xc= +github.com/joy999/nacos-sdk-go v0.0.0-20231120071639-10a34b3e7288 h1:GuL6co0J2oMb2Rd/hbxZfJz1QlZr+DpIsz3Wcvok65o= +github.com/joy999/nacos-sdk-go v0.0.0-20231120071639-10a34b3e7288/go.mod h1:xF3RcNkFUEIik3RCihkvgORtZXZXlp+OeGK0aUALVYU= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= @@ -241,6 +252,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -270,7 +282,10 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= From 83f08b31355e5e8c85355ed1a01223938d47696c Mon Sep 17 00:00:00 2001 From: John Guo Date: Mon, 20 Nov 2023 20:47:26 +0800 Subject: [PATCH 19/22] fix issue in Join stements with prefix specified for package gdb (#3151) --- cmd/gf/go.sum | 14 ++ contrib/drivers/mssql/mssql_z_model_test.go | 5 +- contrib/drivers/mysql/mysql_model_test.go | 43 +++++ .../drivers/mysql/testdata/fix_gdb_join.sql | 151 ++++++++++++++++++ .../mysql/testdata/fix_gdb_join_expect.sql | 1 + contrib/drivers/oracle/oracle_z_model_test.go | 2 + contrib/drivers/sqlite/sqlite_model_test.go | 2 + .../drivers/sqlitecgo/sqlite_model_test.go | 2 + database/gdb/gdb.go | 2 +- database/gdb/gdb_core.go | 46 +++--- database/gdb/gdb_func.go | 2 +- database/gdb/gdb_model.go | 86 +++++----- database/gdb/gdb_model_fields.go | 32 ++-- database/gdb/gdb_model_join.go | 21 ++- database/gdb/gdb_model_utility.go | 15 +- 15 files changed, 344 insertions(+), 80 deletions(-) create mode 100644 contrib/drivers/mysql/testdata/fix_gdb_join.sql create mode 100644 contrib/drivers/mysql/testdata/fix_gdb_join_expect.sql diff --git a/cmd/gf/go.sum b/cmd/gf/go.sum index bb5f8a4a8..533674fa5 100644 --- a/cmd/gf/go.sum +++ b/cmd/gf/go.sum @@ -38,6 +38,20 @@ github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiU github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.5.6 h1:yziPSf9AycEWphv9WiNjcRAVPOJtUauMMvP6pHQB4jY= +github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.5.6/go.mod h1:yOlpwhFXgW+P2sf4goA20PUtxdVLliBx4dJRyJeOtto= +github.com/gogf/gf/contrib/drivers/mssql/v2 v2.5.6 h1:LGQIe5IvYVr4hZ/vUAFiqWssxE7QeILyVPJ9swo1Cmk= +github.com/gogf/gf/contrib/drivers/mssql/v2 v2.5.6/go.mod h1:EcF8v8jqCV61/YqN6DXxdo3kh8waGmEj6WpFqbLkkrM= +github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.6 h1:oR9F4LVoKa/fjf/o6Y/CQRNiYy35Bszo07WwvMWYMxo= +github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.6/go.mod h1:gvHSRqCpv2c+N0gDHsEldHgU/yM9tcCBdIEKZ32/TaE= +github.com/gogf/gf/contrib/drivers/oracle/v2 v2.5.6 h1:3Y3lEoO9SoG1AmfaKjgTsDt93+T2q/qTMog8wBvIIGM= +github.com/gogf/gf/contrib/drivers/oracle/v2 v2.5.6/go.mod h1:cR3lFoU6ZtSaMQ3DpCJwWnYW6EvHPYGGeqv/kzgH4gw= +github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.5.6 h1:0WHVzqITqIBu/NNPXt3tN2eiWAGiNjs9sg6wh+WbUvY= +github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.5.6/go.mod h1:qZCTNQ0n2gHcuBwM9wUl3pelync3xK0gTnChJZD6f0I= +github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.5.6 h1:6clfLvFoHXHdw+skmXg4yxw+cLwgAG8gRiS/6f9Y9Xc= +github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.5.6/go.mod h1:QV6Rrj+4G4OaJVkP9XXRZ1LWL+ls6qH7ebeMcxsulqA= +github.com/gogf/gf/v2 v2.5.6 h1:a1UK1yUP3s+l+vPxmV91+8gTarAP9b1IEOw0W7LNl6E= +github.com/gogf/gf/v2 v2.5.6/go.mod h1:17K/gBYrp0bHGC3XYC7bSPoywmZ6MrZHrZakTfh4eIQ= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= diff --git a/contrib/drivers/mssql/mssql_z_model_test.go b/contrib/drivers/mssql/mssql_z_model_test.go index 2310493a3..7a809039f 100644 --- a/contrib/drivers/mssql/mssql_z_model_test.go +++ b/contrib/drivers/mssql/mssql_z_model_test.go @@ -9,10 +9,11 @@ package mssql_test import ( "database/sql" "fmt" - "github.com/gogf/gf/v2/util/gconv" "testing" "time" + "github.com/gogf/gf/v2/util/gconv" + "github.com/gogf/gf/v2/container/garray" "github.com/gogf/gf/v2/container/gmap" "github.com/gogf/gf/v2/database/gdb" @@ -1906,12 +1907,14 @@ func Test_Model_HasTable(t *testing.T) { defer dropTable(table) gtest.C(t, func(t *gtest.T) { + t.AssertNil(db.GetCore().ClearCacheAll(ctx)) result, err := db.GetCore().HasTable(table) t.Assert(result, true) t.AssertNil(err) }) gtest.C(t, func(t *gtest.T) { + t.AssertNil(db.GetCore().ClearCacheAll(ctx)) result, err := db.GetCore().HasTable("table12321") t.Assert(result, false) t.AssertNil(err) diff --git a/contrib/drivers/mysql/mysql_model_test.go b/contrib/drivers/mysql/mysql_model_test.go index 230100f76..1a2c7e1f1 100644 --- a/contrib/drivers/mysql/mysql_model_test.go +++ b/contrib/drivers/mysql/mysql_model_test.go @@ -3097,12 +3097,14 @@ func Test_Model_HasTable(t *testing.T) { defer dropTable(table) gtest.C(t, func(t *gtest.T) { + t.AssertNil(db.GetCore().ClearCacheAll(ctx)) result, err := db.GetCore().HasTable(table) t.Assert(result, true) t.AssertNil(err) }) gtest.C(t, func(t *gtest.T) { + t.AssertNil(db.GetCore().ClearCacheAll(ctx)) result, err := db.GetCore().HasTable("table12321") t.Assert(result, false) t.AssertNil(err) @@ -4706,3 +4708,44 @@ func Test_Scan_Nil_Result_Error(t *testing.T) { t.Assert(err, sql.ErrNoRows) }) } + +func Test_Model_FixGdbJoin(t *testing.T) { + array := gstr.SplitAndTrim(gtest.DataContent(`fix_gdb_join.sql`), ";") + for _, v := range array { + if _, err := db.Exec(ctx, v); err != nil { + gtest.Error(err) + } + } + defer dropTable(`common_resource`) + defer dropTable(`managed_resource`) + defer dropTable(`rules_template`) + defer dropTable(`resource_mark`) + gtest.C(t, func(t *gtest.T) { + t.AssertNil(db.GetCore().ClearCacheAll(ctx)) + sqlSlice, err := gdb.CatchSQL(ctx, func(ctx context.Context) error { + orm := db.Model(`managed_resource`).Ctx(ctx). + LeftJoinOnField(`common_resource`, `resource_id`). + LeftJoinOnFields(`resource_mark`, `resource_mark_id`, `=`, `id`). + LeftJoinOnFields(`rules_template`, `rule_template_id`, `=`, `template_id`). + FieldsPrefix( + `managed_resource`, + "resource_id", "user", "status", "status_message", "safe_publication", "rule_template_id", + "created_at", "comments", "expired_at", "resource_mark_id", "instance_id", "resource_name", + "pay_mode"). + FieldsPrefix(`resource_mark`, "mark_name", "color"). + FieldsPrefix(`rules_template`, "name"). + FieldsPrefix(`common_resource`, `src_instance_id`, "database_kind", "source_type", "ip", "port") + all, err := orm.OrderAsc("src_instance_id").All() + t.Assert(len(all), 4) + t.Assert(all[0]["pay_mode"], 1) + t.Assert(all[0]["src_instance_id"], 2) + t.Assert(all[3]["instance_id"], "dmcins-jxy0x75m") + t.Assert(all[3]["src_instance_id"], "vdb-6b6m3u1u") + t.Assert(all[3]["resource_mark_id"], "11") + return err + }) + t.AssertNil(err) + + t.Assert(gtest.DataContent(`fix_gdb_join_expect.sql`), sqlSlice[len(sqlSlice)-1]) + }) +} diff --git a/contrib/drivers/mysql/testdata/fix_gdb_join.sql b/contrib/drivers/mysql/testdata/fix_gdb_join.sql new file mode 100644 index 000000000..48cf1efb3 --- /dev/null +++ b/contrib/drivers/mysql/testdata/fix_gdb_join.sql @@ -0,0 +1,151 @@ + + +DROP TABLE IF EXISTS `common_resource`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `common_resource` ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `app_id` bigint(20) NOT NULL, + `resource_id` varchar(64) NOT NULL, + `src_instance_id` varchar(64) DEFAULT NULL, + `region` varchar(36) DEFAULT NULL, + `zone` varchar(36) DEFAULT NULL, + `database_kind` varchar(20) NOT NULL, + `source_type` varchar(64) NOT NULL, + `ip` varchar(64) DEFAULT NULL, + `port` int(10) DEFAULT NULL, + `vpc_id` varchar(20) DEFAULT NULL, + `subnet_id` varchar(20) DEFAULT NULL, + `proxy_ip` varchar(64) DEFAULT NULL, + `proxy_port` int(10) DEFAULT NULL, + `proxy_id` bigint(20) DEFAULT NULL, + `proxy_snat_ip` varchar(64) DEFAULT NULL, + `lease_at` timestamp NULL DEFAULT NULL, + `uin` varchar(32) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_resource` (`app_id`,`src_instance_id`,`vpc_id`,`subnet_id`,`ip`,`port`), + KEY `resource_id` (`resource_id`) +) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4 COMMENT='资源公共信息表'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `common_resource` +-- + +LOCK TABLES `common_resource` WRITE; +/*!40000 ALTER TABLE `common_resource` DISABLE KEYS */; +INSERT INTO `common_resource` VALUES (1,1,'2','2','2','3','1','1','1',1,'1','1','1',1,1,'1',NULL,''),(3,2,'3','3','3','3','3','3','3',3,'3','3','3',3,3,'3',NULL,''),(18,1303697168,'dmc-rgnh9qre','vdb-6b6m3u1u','ap-guangzhou','','vdb','cloud','10.0.1.16',80,'vpc-m3dchft7','subnet-9as3a3z2','9.27.72.189',11131,228476,'169.254.128.5, ','2023-11-08 08:13:04',''),(20,1303697168,'dmc-4grzi4jg','tdsqlshard-313spncx','ap-guangzhou','','tdsql','cloud','10.255.0.27',3306,'vpc-407k0e8x','subnet-qhkkk3bo','30.86.239.200',24087,0,'',NULL,''); +/*!40000 ALTER TABLE `common_resource` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `managed_resource` +-- + +DROP TABLE IF EXISTS `managed_resource`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `managed_resource` ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `instance_id` varchar(64) NOT NULL, + `resource_id` varchar(64) NOT NULL, + `resource_name` varchar(64) DEFAULT NULL, + `status` varchar(36) NOT NULL DEFAULT 'valid', + `status_message` varchar(64) DEFAULT NULL, + `user` varchar(64) NOT NULL, + `password` varchar(1024) NOT NULL, + `pay_mode` tinyint(1) DEFAULT '0', + `safe_publication` bit(1) DEFAULT b'0', + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `expired_at` timestamp NULL DEFAULT NULL, + `deleted` tinyint(1) NOT NULL DEFAULT '0', + `resource_mark_id` int(11) DEFAULT NULL, + `comments` varchar(64) DEFAULT NULL, + `rule_template_id` varchar(64) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `resource_id` (`resource_id`), + KEY `instance_id` (`instance_id`) +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COMMENT='管控实例表'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `managed_resource` +-- + +LOCK TABLES `managed_resource` WRITE; +/*!40000 ALTER TABLE `managed_resource` DISABLE KEYS */; +INSERT INTO `managed_resource` VALUES (1,'2','3','1','1','1','1','1',1,_binary '','2023-11-06 12:14:21','2023-11-06 12:14:21',NULL,1,1,'1',''),(2,'3','2','1','1','1','1','1',1,_binary '\0','2023-11-06 12:15:07','2023-11-06 12:15:07',NULL,1,2,'1',''),(5,'dmcins-jxy0x75m','dmc-rgnh9qre','erichmao-vdb-test','invalid','The Ip field is required','root','2e39af3dd1d447e2b1437b40c62c35995fa22b370c7455ff7815dace3a6e8891ccadcfc893fe1342a4102d742bd7a3e603cd0ac1fcdc072d7c0b5be5836ec87306981b629f9b59aedf0316e9504ab172fa1c95756d5b260114e4feaa0b19223fb61cb268cc4818307ed193dbab830cf556b91cde182686eb70f70ea77f69eff66230dec2ce92bd3352cad31abf47597a5cc6a0d638381dc3bae7aa1b142730790a6d4cefdef1bd460061c966ad5008c2b5fc971b7f4d7dddffa5b1456c45e2917763dd8fffb1fa7fc4783feca95dafc9a9f4edf21b0579f76b0a3154f087e3b9a7fc49af8ff92b12e7b03caa865e72e777dd9d35a11910df0d55ead90e47d5f8',1,_binary '','2023-11-08 08:13:20','2023-11-09 05:31:07',NULL,0,11,NULL,'12345'),(6,'dmcins-erxms6ya','dmc-4grzi4jg','erichmao-vdb-test','invalid','The Ip field is required','leotaowang','641d846cf75bc7944202251d97dca8335f7f149dd4fd911ca5b87c71ef1dc5d0a66c4e5021ef7ad53136cda2fb2567d34e3dd1a7666e3f64ebf532eb2a55d84952aac86b4211f563f7b9da7dd0f88ec288d6680d3513cea0c1b7ad7babb474717f77ebbc9d63bb458adaf982887da9e63df957ffda572c1c3ed187471b99fdc640b45fed76a6d50dc1090eee79b4d94d056c4d43416133481f55bd040759398680104a84d801e6475dcfe919a00859908296747430b728a00c8d54256ae220235a138e0bbf08fe8b6fc8589971436b55bff966154721a91adbdc9c2b6f50ef5849ed77e5b028116abac51584b8d401cd3a88d18df127006358ed33fc3fa6f480',1,_binary '','2023-11-08 22:15:17','2023-11-09 05:31:07',NULL,0,11,NULL,'12345'); +/*!40000 ALTER TABLE `managed_resource` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `rules_template` +-- + +DROP TABLE IF EXISTS `rules_template`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `rules_template` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `app_id` bigint(20) DEFAULT NULL, + `name` varchar(255) NOT NULL, + `database_kind` varchar(64) DEFAULT NULL, + `is_default` tinyint(1) NOT NULL DEFAULT '0', + `win_rules` varchar(2048) DEFAULT NULL, + `inception_rules` varchar(2048) DEFAULT NULL, + `auto_exec_rules` varchar(2048) DEFAULT NULL, + `order_check_step` varchar(2048) DEFAULT NULL, + `template_id` varchar(64) NOT NULL DEFAULT '', + `version` int(11) NOT NULL DEFAULT '1', + `deleted` tinyint(1) NOT NULL DEFAULT '0', + `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `update_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `is_system` tinyint(1) NOT NULL DEFAULT '0', + `uin` varchar(64) DEFAULT NULL, + `subAccountUin` varchar(64) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `uniq_template_id` (`template_id`), + UNIQUE KEY `uniq_name` (`name`,`app_id`,`deleted`,`uin`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `rules_template` +-- + +LOCK TABLES `rules_template` WRITE; +/*!40000 ALTER TABLE `rules_template` DISABLE KEYS */; +/*!40000 ALTER TABLE `rules_template` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `resource_mark` +-- + +DROP TABLE IF EXISTS `resource_mark`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `resource_mark` ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `app_id` bigint(20) NOT NULL, + `mark_name` varchar(64) NOT NULL, + `color` varchar(11) NOT NULL, + `creator` varchar(32) NOT NULL, + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `app_id_name` (`app_id`,`mark_name`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COMMENT='标签信息表'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `resource_mark` +-- + +LOCK TABLES `resource_mark` WRITE; +/*!40000 ALTER TABLE `resource_mark` DISABLE KEYS */; +INSERT INTO `resource_mark` VALUES (10,1,'test','red','1','2023-11-06 02:45:46','2023-11-06 02:45:46'); +/*!40000 ALTER TABLE `resource_mark` ENABLE KEYS */; +UNLOCK TABLES; + diff --git a/contrib/drivers/mysql/testdata/fix_gdb_join_expect.sql b/contrib/drivers/mysql/testdata/fix_gdb_join_expect.sql new file mode 100644 index 000000000..c391675cb --- /dev/null +++ b/contrib/drivers/mysql/testdata/fix_gdb_join_expect.sql @@ -0,0 +1 @@ +SELECT managed_resource.resource_id,managed_resource.user,managed_resource.status,managed_resource.status_message,managed_resource.safe_publication,managed_resource.rule_template_id,managed_resource.created_at,managed_resource.comments,managed_resource.expired_at,managed_resource.resource_mark_id,managed_resource.instance_id,managed_resource.resource_name,managed_resource.pay_mode,resource_mark.mark_name,resource_mark.color,rules_template.name,common_resource.src_instance_id,common_resource.database_kind,common_resource.source_type,common_resource.ip,common_resource.port FROM `managed_resource` LEFT JOIN `common_resource` ON (`managed_resource`.`resource_id`=`common_resource`.`resource_id`) LEFT JOIN `resource_mark` ON (`managed_resource`.`resource_mark_id` = `resource_mark`.`id`) LEFT JOIN `rules_template` ON (`managed_resource`.`rule_template_id` = `rules_template`.`template_id`) ORDER BY `src_instance_id` ASC \ No newline at end of file diff --git a/contrib/drivers/oracle/oracle_z_model_test.go b/contrib/drivers/oracle/oracle_z_model_test.go index 1ab58ddd3..d50d46cfe 100644 --- a/contrib/drivers/oracle/oracle_z_model_test.go +++ b/contrib/drivers/oracle/oracle_z_model_test.go @@ -950,12 +950,14 @@ func Test_Model_HasTable(t *testing.T) { defer dropTable(table) // db.SetDebug(true) gtest.C(t, func(t *gtest.T) { + t.AssertNil(db.GetCore().ClearCacheAll(ctx)) result, err := db.GetCore().HasTable(strings.ToUpper(table)) t.Assert(result, true) t.AssertNil(err) }) gtest.C(t, func(t *gtest.T) { + t.AssertNil(db.GetCore().ClearCacheAll(ctx)) result, err := db.GetCore().HasTable("table12321") t.Assert(result, false) t.AssertNil(err) diff --git a/contrib/drivers/sqlite/sqlite_model_test.go b/contrib/drivers/sqlite/sqlite_model_test.go index f39804f1e..a6d6f61a5 100644 --- a/contrib/drivers/sqlite/sqlite_model_test.go +++ b/contrib/drivers/sqlite/sqlite_model_test.go @@ -2807,12 +2807,14 @@ func Test_Model_HasTable(t *testing.T) { defer dropTable(table) gtest.C(t, func(t *gtest.T) { + t.AssertNil(db.GetCore().ClearCacheAll(ctx)) result, err := db.GetCore().HasTable(table) t.Assert(result, true) t.AssertNil(err) }) gtest.C(t, func(t *gtest.T) { + t.AssertNil(db.GetCore().ClearCacheAll(ctx)) result, err := db.GetCore().HasTable("table12321") t.Assert(result, false) t.AssertNil(err) diff --git a/contrib/drivers/sqlitecgo/sqlite_model_test.go b/contrib/drivers/sqlitecgo/sqlite_model_test.go index 8aa297e7a..b9f1760d1 100644 --- a/contrib/drivers/sqlitecgo/sqlite_model_test.go +++ b/contrib/drivers/sqlitecgo/sqlite_model_test.go @@ -2835,12 +2835,14 @@ func Test_Model_HasTable(t *testing.T) { defer dropTable(table) gtest.C(t, func(t *gtest.T) { + t.AssertNil(db.GetCore().ClearCacheAll(ctx)) result, err := db.GetCore().HasTable(table) t.Assert(result, true) t.AssertNil(err) }) gtest.C(t, func(t *gtest.T) { + t.AssertNil(db.GetCore().ClearCacheAll(ctx)) result, err := db.GetCore().HasTable("table12321") t.Assert(result, false) t.AssertNil(err) diff --git a/database/gdb/gdb.go b/database/gdb/gdb.go index 1c3344149..e0ddc0329 100644 --- a/database/gdb/gdb.go +++ b/database/gdb/gdb.go @@ -353,7 +353,7 @@ type ( type CatchSQLManager struct { SQLArray *garray.StrArray - DoCommit bool + DoCommit bool // DoCommit marks it will be committed to underlying driver or not. } const ( diff --git a/database/gdb/gdb_core.go b/database/gdb/gdb_core.go index f4ac5f781..482caf80b 100644 --- a/database/gdb/gdb_core.go +++ b/database/gdb/gdb_core.go @@ -762,27 +762,37 @@ func (c *Core) writeSqlToLogger(ctx context.Context, sql *Sql) { // HasTable determine whether the table name exists in the database. func (c *Core) HasTable(name string) (bool, error) { - var ( - ctx = c.db.GetCtx() - cacheKey = fmt.Sprintf(`HasTable: %s`, name) - ) - result, err := c.GetCache().GetOrSetFuncLock(ctx, cacheKey, func(ctx context.Context) (interface{}, error) { - tableList, err := c.db.Tables(ctx) - if err != nil { - return false, err - } - for _, table := range tableList { - if table == name { - return true, nil - } - } - return false, nil - }, 0, - ) + tables, err := c.GetTablesWithCache() if err != nil { return false, err } - return result.Bool(), nil + for _, table := range tables { + if table == name { + return true, nil + } + } + return false, nil +} + +// GetTablesWithCache retrieves and returns the table names of current database with cache. +func (c *Core) GetTablesWithCache() ([]string, error) { + var ( + ctx = c.db.GetCtx() + cacheKey = fmt.Sprintf(`Tables: %s`, c.db.GetGroup()) + ) + result, err := c.GetCache().GetOrSetFuncLock( + ctx, cacheKey, func(ctx context.Context) (interface{}, error) { + tableList, err := c.db.Tables(ctx) + if err != nil { + return false, err + } + return tableList, nil + }, 0, + ) + if err != nil { + return nil, err + } + return result.Strings(), nil } // isSoftCreatedFieldName checks and returns whether given field name is an automatic-filled created time. diff --git a/database/gdb/gdb_func.go b/database/gdb/gdb_func.go index 7df37ce3a..28710a203 100644 --- a/database/gdb/gdb_func.go +++ b/database/gdb/gdb_func.go @@ -96,7 +96,7 @@ func DBFromCtx(ctx context.Context) DB { return nil } -// ToSQL formats and returns the last one of sql statements in given closure function. +// ToSQL formats and returns the last one of sql statements in given closure function without truly executing it. func ToSQL(ctx context.Context, f func(ctx context.Context) error) (sql string, err error) { var manager = &CatchSQLManager{ SQLArray: garray.NewStrArray(), diff --git a/database/gdb/gdb_model.go b/database/gdb/gdb_model.go index 5e70154b9..dc8f596ba 100644 --- a/database/gdb/gdb_model.go +++ b/database/gdb/gdb_model.go @@ -17,39 +17,40 @@ import ( // Model is core struct implementing the DAO for ORM. type Model struct { - db DB // Underlying DB interface. - tx TX // Underlying TX interface. - rawSql string // rawSql is the raw SQL string which marks a raw SQL based Model not a table based Model. - schema string // Custom database schema. - linkType int // Mark for operation on master or slave. - tablesInit string // Table names when model initialization. - tables string // Operation table names, which can be more than one table names and aliases, like: "user", "user u", "user u, user_detail ud". - fields string // Operation fields, multiple fields joined using char ','. - fieldsEx string // Excluded operation fields, multiple fields joined using char ','. - withArray []interface{} // Arguments for With feature. - withAll bool // Enable model association operations on all objects that have "with" tag in the struct. - extraArgs []interface{} // Extra custom arguments for sql, which are prepended to the arguments before sql committed to underlying driver. - whereBuilder *WhereBuilder // Condition builder for where operation. - groupBy string // Used for "group by" statement. - orderBy string // Used for "order by" statement. - having []interface{} // Used for "having..." statement. - start int // Used for "select ... start, limit ..." statement. - limit int // Used for "select ... start, limit ..." statement. - option int // Option for extra operation features. - offset int // Offset statement for some databases grammar. - partition string // Partition table partition name. - data interface{} // Data for operation, which can be type of map/[]map/struct/*struct/string, etc. - batch int // Batch number for batch Insert/Replace/Save operations. - filter bool // Filter data and where key-value pairs according to the fields of the table. - distinct string // Force the query to only return distinct results. - lockInfo string // Lock for update or in shared lock. - cacheEnabled bool // Enable sql result cache feature, which is mainly for indicating cache duration(especially 0) usage. - cacheOption CacheOption // Cache option for query statement. - hookHandler HookHandler // Hook functions for model hook feature. - unscoped bool // Disables soft deleting features when select/delete operations. - safe bool // If true, it clones and returns a new model object whenever operation done; or else it changes the attribute of current model. - onDuplicate interface{} // onDuplicate is used for ON "DUPLICATE KEY UPDATE" statement. - onDuplicateEx interface{} // onDuplicateEx is used for excluding some columns ON "DUPLICATE KEY UPDATE" statement. + db DB // Underlying DB interface. + tx TX // Underlying TX interface. + rawSql string // rawSql is the raw SQL string which marks a raw SQL based Model not a table based Model. + schema string // Custom database schema. + linkType int // Mark for operation on master or slave. + tablesInit string // Table names when model initialization. + tables string // Operation table names, which can be more than one table names and aliases, like: "user", "user u", "user u, user_detail ud". + fields string // Operation fields, multiple fields joined using char ','. + fieldsEx string // Excluded operation fields, multiple fields joined using char ','. + withArray []interface{} // Arguments for With feature. + withAll bool // Enable model association operations on all objects that have "with" tag in the struct. + extraArgs []interface{} // Extra custom arguments for sql, which are prepended to the arguments before sql committed to underlying driver. + whereBuilder *WhereBuilder // Condition builder for where operation. + groupBy string // Used for "group by" statement. + orderBy string // Used for "order by" statement. + having []interface{} // Used for "having..." statement. + start int // Used for "select ... start, limit ..." statement. + limit int // Used for "select ... start, limit ..." statement. + option int // Option for extra operation features. + offset int // Offset statement for some databases grammar. + partition string // Partition table partition name. + data interface{} // Data for operation, which can be type of map/[]map/struct/*struct/string, etc. + batch int // Batch number for batch Insert/Replace/Save operations. + filter bool // Filter data and where key-value pairs according to the fields of the table. + distinct string // Force the query to only return distinct results. + lockInfo string // Lock for update or in shared lock. + cacheEnabled bool // Enable sql result cache feature, which is mainly for indicating cache duration(especially 0) usage. + cacheOption CacheOption // Cache option for query statement. + hookHandler HookHandler // Hook functions for model hook feature. + unscoped bool // Disables soft deleting features when select/delete operations. + safe bool // If true, it clones and returns a new model object whenever operation done; or else it changes the attribute of current model. + onDuplicate interface{} // onDuplicate is used for ON "DUPLICATE KEY UPDATE" statement. + onDuplicateEx interface{} // onDuplicateEx is used for excluding some columns ON "DUPLICATE KEY UPDATE" statement. + tableAliasMap map[string]string // Table alias to true table name, usually used in join statements. } // ModelHandler is a function that handles given Model and returns a new Model that is custom modified. @@ -125,15 +126,16 @@ func (c *Core) Model(tableNameQueryOrStruct ...interface{}) *Model { } } m := &Model{ - db: c.db, - schema: c.schema, - tablesInit: tableStr, - tables: tableStr, - fields: defaultFields, - start: -1, - offset: -1, - filter: true, - extraArgs: extraArgs, + db: c.db, + schema: c.schema, + tablesInit: tableStr, + tables: tableStr, + fields: defaultFields, + start: -1, + offset: -1, + filter: true, + extraArgs: extraArgs, + tableAliasMap: make(map[string]string), } m.whereBuilder = m.Builder() if defaultModelSafe { diff --git a/database/gdb/gdb_model_fields.go b/database/gdb/gdb_model_fields.go index a9a54711c..c9e29a3f8 100644 --- a/database/gdb/gdb_model_fields.go +++ b/database/gdb/gdb_model_fields.go @@ -27,7 +27,7 @@ func (m *Model) Fields(fieldNamesOrMapStruct ...interface{}) *Model { if length == 0 { return m } - fields := m.getFieldsFrom(fieldNamesOrMapStruct...) + fields := m.getFieldsFrom(m.tablesInit, fieldNamesOrMapStruct...) if len(fields) == 0 { return m } @@ -35,12 +35,12 @@ func (m *Model) Fields(fieldNamesOrMapStruct ...interface{}) *Model { } // FieldsPrefix performs as function Fields but add extra prefix for each field. -func (m *Model) FieldsPrefix(prefix string, fieldNamesOrMapStruct ...interface{}) *Model { - fields := m.getFieldsFrom(fieldNamesOrMapStruct...) +func (m *Model) FieldsPrefix(prefixOrAlias string, fieldNamesOrMapStruct ...interface{}) *Model { + fields := m.getFieldsFrom(m.getTableNameByPrefixOrAlias(prefixOrAlias), fieldNamesOrMapStruct...) if len(fields) == 0 { return m } - gstr.PrefixArray(fields, prefix+".") + gstr.PrefixArray(fields, prefixOrAlias+".") return m.appendFieldsByStr(gstr.Join(fields, ",")) } @@ -51,11 +51,14 @@ func (m *Model) FieldsPrefix(prefix string, fieldNamesOrMapStruct ...interface{} // // Also see Fields. func (m *Model) FieldsEx(fieldNamesOrMapStruct ...interface{}) *Model { + return m.doFieldsEx(m.tablesInit, fieldNamesOrMapStruct...) +} +func (m *Model) doFieldsEx(table string, fieldNamesOrMapStruct ...interface{}) *Model { length := len(fieldNamesOrMapStruct) if length == 0 { return m } - fields := m.getFieldsFrom(fieldNamesOrMapStruct...) + fields := m.getFieldsFrom(table, fieldNamesOrMapStruct...) if len(fields) == 0 { return m } @@ -63,10 +66,10 @@ func (m *Model) FieldsEx(fieldNamesOrMapStruct ...interface{}) *Model { } // FieldsExPrefix performs as function FieldsEx but add extra prefix for each field. -func (m *Model) FieldsExPrefix(prefix string, fieldNamesOrMapStruct ...interface{}) *Model { - model := m.FieldsEx(fieldNamesOrMapStruct...) +func (m *Model) FieldsExPrefix(prefixOrAlias string, fieldNamesOrMapStruct ...interface{}) *Model { + model := m.doFieldsEx(m.getTableNameByPrefixOrAlias(prefixOrAlias), fieldNamesOrMapStruct...) array := gstr.SplitAndTrim(model.fieldsEx, ",") - gstr.PrefixArray(array, prefix+".") + gstr.PrefixArray(array, prefixOrAlias+".") model.fieldsEx = gstr.Join(array, ",") return model } @@ -185,7 +188,8 @@ func (m *Model) HasField(field string) (bool, error) { return m.db.GetCore().HasField(m.GetCtx(), m.tablesInit, field) } -func (m *Model) getFieldsFrom(fieldNamesOrMapStruct ...interface{}) []string { +// getFieldsFrom retrieves, filters and returns fields name from table `table`. +func (m *Model) getFieldsFrom(table string, fieldNamesOrMapStruct ...interface{}) []string { length := len(fieldNamesOrMapStruct) if length == 0 { return nil @@ -193,23 +197,25 @@ func (m *Model) getFieldsFrom(fieldNamesOrMapStruct ...interface{}) []string { switch { // String slice. case length >= 2: - return m.mappingAndFilterToTableFields(gconv.Strings(fieldNamesOrMapStruct), true) + return m.mappingAndFilterToTableFields( + table, gconv.Strings(fieldNamesOrMapStruct), true, + ) // It needs type asserting. case length == 1: structOrMap := fieldNamesOrMapStruct[0] switch r := structOrMap.(type) { case string: - return m.mappingAndFilterToTableFields([]string{r}, false) + return m.mappingAndFilterToTableFields(table, []string{r}, false) case []string: - return m.mappingAndFilterToTableFields(r, true) + return m.mappingAndFilterToTableFields(table, r, true) case Raw, *Raw: return []string{gconv.String(structOrMap)} default: - return m.mappingAndFilterToTableFields(getFieldsFromStructOrMap(structOrMap), true) + return m.mappingAndFilterToTableFields(table, getFieldsFromStructOrMap(structOrMap), true) } default: diff --git a/database/gdb/gdb_model_join.go b/database/gdb/gdb_model_join.go index eacb0d5a8..2ebc2436d 100644 --- a/database/gdb/gdb_model_join.go +++ b/database/gdb/gdb_model_join.go @@ -159,6 +159,8 @@ func (m *Model) doJoin(operator joinOperator, tableOrSubQueryAndJoinConditions . var ( model = m.getModel() joinStr = "" + table string + alias string ) // Check the first parameter table or sub-query. if len(tableOrSubQueryAndJoinConditions) > 0 { @@ -168,24 +170,29 @@ func (m *Model) doJoin(operator joinOperator, tableOrSubQueryAndJoinConditions . joinStr = "(" + joinStr + ")" } } else { - joinStr = m.db.GetCore().QuotePrefixTableName(tableOrSubQueryAndJoinConditions[0]) + table = tableOrSubQueryAndJoinConditions[0] + joinStr = m.db.GetCore().QuotePrefixTableName(table) } } // Generate join condition statement string. conditionLength := len(tableOrSubQueryAndJoinConditions) switch { case conditionLength > 2: + alias = tableOrSubQueryAndJoinConditions[1] model.tables += fmt.Sprintf( " %s JOIN %s AS %s ON (%s)", operator, joinStr, - m.db.GetCore().QuoteWord(tableOrSubQueryAndJoinConditions[1]), + m.db.GetCore().QuoteWord(alias), tableOrSubQueryAndJoinConditions[2], ) + m.tableAliasMap[alias] = table + case conditionLength == 2: model.tables += fmt.Sprintf( " %s JOIN %s ON (%s)", operator, joinStr, tableOrSubQueryAndJoinConditions[1], ) + case conditionLength == 1: model.tables += fmt.Sprintf( " %s JOIN %s", operator, joinStr, @@ -194,6 +201,16 @@ func (m *Model) doJoin(operator joinOperator, tableOrSubQueryAndJoinConditions . return model } +// getTableNameByPrefixOrAlias checks and returns the table name if `prefixOrAlias` is an alias of a table, +// it or else returns the `prefixOrAlias` directly. +func (m *Model) getTableNameByPrefixOrAlias(prefixOrAlias string) string { + value, ok := m.tableAliasMap[prefixOrAlias] + if ok { + return value + } + return prefixOrAlias +} + // isSubQuery checks and returns whether given string a sub-query sql string. func isSubQuery(s string) bool { s = gstr.TrimLeft(s, "()") diff --git a/database/gdb/gdb_model_utility.go b/database/gdb/gdb_model_utility.go index fbf51f7c9..0873af25f 100644 --- a/database/gdb/gdb_model_utility.go +++ b/database/gdb/gdb_model_utility.go @@ -52,8 +52,19 @@ func (m *Model) getModel() *Model { // Eg: // ID -> id // NICK_Name -> nickname. -func (m *Model) mappingAndFilterToTableFields(fields []string, filter bool) []string { - fieldsMap, _ := m.TableFields(m.tablesInit) +func (m *Model) mappingAndFilterToTableFields(table string, fields []string, filter bool) []string { + var fieldsTable = table + if fieldsTable != "" { + hasTable, _ := m.db.GetCore().HasTable(fieldsTable) + if !hasTable { + fieldsTable = m.tablesInit + } + } + if fieldsTable == "" { + fieldsTable = m.tablesInit + } + + fieldsMap, _ := m.TableFields(fieldsTable) if len(fieldsMap) == 0 { return fields } From b1754f8254b90e23de5f6995c9507e22b9e481e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=B7=E4=BA=AE?= <739476267@qq.com> Date: Wed, 22 Nov 2023 20:49:07 +0800 Subject: [PATCH 20/22] script updates for version upgrading (#3169) --- .set_version.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.set_version.sh b/.set_version.sh index 27f4f4260..5789cab7f 100755 --- a/.set_version.sh +++ b/.set_version.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash - if [ $# -ne 2 ]; then echo "Parameter exception, please execute in the format of $0 [directory] [version number]" echo "PS:$0 ./ v2.4.0" @@ -20,6 +19,13 @@ workdir=. newVersion=$2 echo "Prepare to replace the GF library version numbers in all go.mod files in the ${workdir} directory with ${newVersion}" +# check find command support or not +output=$(find "${workdir}" -name go.mod 2>&1) +if [[ $? -ne 0 ]]; then + echo "Error: please use bash or zsh to run!" + exit 1 +fi + if [[ true ]]; then echo "package gf" > version.go echo "" >> version.go From ea5d52cb2f0b8484ed2c3a84f1621ccf374c8477 Mon Sep 17 00:00:00 2001 From: John Guo Date: Wed, 22 Nov 2023 21:05:39 +0800 Subject: [PATCH 21/22] fix issue #3147 (#3161) --- cmd/gf/internal/cmd/cmd.go | 2 + os/gcmd/gcmd.go | 2 + os/gcmd/gcmd_command.go | 11 +- os/gcmd/gcmd_command_object.go | 18 ++- os/gcmd/gcmd_command_run.go | 8 +- os/gcmd/gcmd_z_unit_feature_object1_test.go | 25 ++- util/gconv/gconv_maptomaps.go | 6 +- util/gconv/gconv_scan.go | 10 +- util/gconv/gconv_struct.go | 163 +++++++++++++------- util/gconv/gconv_structs.go | 12 +- util/gconv/gconv_z_unit_scan_test.go | 27 ++++ 11 files changed, 187 insertions(+), 97 deletions(-) diff --git a/cmd/gf/internal/cmd/cmd.go b/cmd/gf/internal/cmd/cmd.go index 7d20aedda..bd5e8922e 100644 --- a/cmd/gf/internal/cmd/cmd.go +++ b/cmd/gf/internal/cmd/cmd.go @@ -55,6 +55,7 @@ func (c cGF) Index(ctx context.Context, in cGFInput) (out *cGFOutput, err error) _, err = Version.Index(ctx, cVersionInput{}) return } + answer := "n" // No argument or option, do installation checks. if data, isInstalled := service.Install.IsInstalled(); !isInstalled { @@ -71,6 +72,7 @@ func (c cGF) Index(ctx context.Context, in cGFInput) (out *cGFOutput, err error) gcmd.Scan("press `Enter` to exit...") return } + // Print help content. gcmd.CommandFromCtx(ctx).Print() return diff --git a/os/gcmd/gcmd.go b/os/gcmd/gcmd.go index 139b60c82..41b7eff03 100644 --- a/os/gcmd/gcmd.go +++ b/os/gcmd/gcmd.go @@ -28,6 +28,8 @@ const ( helpOptionNameShort = "h" maxLineChars = 120 tracingInstrumentName = "github.com/gogf/gf/v2/os/gcmd.Command" + tagNameName = "name" + tagNameShort = "short" ) // Init does custom initialization. diff --git a/os/gcmd/gcmd_command.go b/os/gcmd/gcmd_command.go index d3cfc2b78..557a7531c 100644 --- a/os/gcmd/gcmd_command.go +++ b/os/gcmd/gcmd_command.go @@ -42,12 +42,11 @@ type FuncWithValue func(ctx context.Context, parser *Parser) (out interface{}, e // Argument is the command value that are used by certain command. type Argument struct { - Name string // Option name. - FieldName string // Option field name. - Short string // Option short. - Brief string // Brief info about this Option, which is used in help info. - IsArg bool // IsArg marks this argument taking value from command line argument instead of option. - Orphan bool // Whether this Option having or having no value bound to it. + Name string // Option name. + Short string // Option short. + Brief string // Brief info about this Option, which is used in help info. + IsArg bool // IsArg marks this argument taking value from command line argument instead of option. + Orphan bool // Whether this Option having or having no value bound to it. } var ( diff --git a/os/gcmd/gcmd_command_object.go b/os/gcmd/gcmd_command_object.go index ab9d3d7cb..68c8610ad 100644 --- a/os/gcmd/gcmd_command_object.go +++ b/os/gcmd/gcmd_command_object.go @@ -353,9 +353,6 @@ func newArgumentsFromInput(object interface{}) (args []Argument, err error) { } if arg.Name == "" { arg.Name = field.Name() - } else if arg.Name != field.Name() { - arg.FieldName = field.Name() - nameSet.Add(arg.FieldName) } if arg.Name == helpOptionName { return nil, gerror.Newf( @@ -411,14 +408,25 @@ func mergeDefaultStructValue(data map[string]interface{}, pointer interface{}) e foundValue interface{} ) for _, field := range tagFields { + var ( + nameValue = field.Tag(tagNameName) + shortValue = field.Tag(tagNameShort) + ) + // If it already has value, it then ignores the default value. + if value, ok := data[nameValue]; ok { + data[field.Name()] = value + continue + } + if value, ok := data[shortValue]; ok { + data[field.Name()] = value + continue + } foundKey, foundValue = gutil.MapPossibleItemByKey(data, field.Name()) if foundKey == "" { data[field.Name()] = field.TagValue } else { if utils.IsEmpty(foundValue) { data[foundKey] = field.TagValue - } else { - data[field.Name()] = foundValue } } } diff --git a/os/gcmd/gcmd_command_run.go b/os/gcmd/gcmd_command_run.go index 7aa61f95d..c3f6fd53c 100644 --- a/os/gcmd/gcmd_command_run.go +++ b/os/gcmd/gcmd_command_run.go @@ -171,12 +171,10 @@ func (c *Command) reParse(ctx context.Context, parser *Parser) (*Parser, error) if arg.IsArg { continue } - optionKey = arg.Name - if arg.FieldName != "" { - optionKey += fmt.Sprintf(`,%s`, arg.FieldName) - } if arg.Short != "" { - optionKey += fmt.Sprintf(`,%s`, arg.Short) + optionKey = fmt.Sprintf(`%s,%s`, arg.Name, arg.Short) + } else { + optionKey = arg.Name } supportedOptions[optionKey] = !arg.Orphan } diff --git a/os/gcmd/gcmd_z_unit_feature_object1_test.go b/os/gcmd/gcmd_z_unit_feature_object1_test.go index a2845b327..c804e7c68 100644 --- a/os/gcmd/gcmd_z_unit_feature_object1_test.go +++ b/os/gcmd/gcmd_z_unit_feature_object1_test.go @@ -30,12 +30,14 @@ type TestCmdObjectEnvInput struct { type TestCmdObjectEnvOutput struct{} type TestCmdObjectTestInput struct { - g.Meta `name:"test" usage:"root test" brief:"root test command" dc:"root test command description" ad:"root test command ad"` - Name string `name:"yourname" v:"required" short:"n" orphan:"false" brief:"name for test command" d:"tom"` + g.Meta `name:"test" usage:"root test" brief:"root test command" dc:"root test command description" ad:"root test command ad"` + Name string `name:"yourname" v:"required" short:"n" orphan:"false" brief:"name for test command" d:"tom"` + Version bool `name:"version" short:"v" orphan:"true" brief:"show version"` } type TestCmdObjectTestOutput struct { - Content string + Name string + Version bool } func (TestCmdObject) Env(ctx context.Context, in TestCmdObjectEnvInput) (out *TestCmdObjectEnvOutput, err error) { @@ -44,7 +46,8 @@ func (TestCmdObject) Env(ctx context.Context, in TestCmdObjectEnvInput) (out *Te func (TestCmdObject) Test(ctx context.Context, in TestCmdObjectTestInput) (out *TestCmdObjectTestOutput, err error) { out = &TestCmdObjectTestOutput{ - Content: in.Name, + Name: in.Name, + Version: in.Version, } return } @@ -93,19 +96,25 @@ func Test_Command_NewFromObject_RunWithValue(t *testing.T) { os.Args = []string{"root", "test", "-n=john"} value, err := cmd.RunWithValueError(ctx) t.AssertNil(err) - t.Assert(value, `{"Content":"john"}`) + t.Assert(value, `{"Name":"john","Version":false}`) // test name tag name os.Args = []string{"root", "test", "-yourname=hailaz"} value1, err1 := cmd.RunWithValueError(ctx) t.AssertNil(err1) - t.Assert(value1, `{"Content":"hailaz"}`) + t.Assert(value1, `{"Name":"hailaz","Version":false}`) // test default tag value os.Args = []string{"root", "test"} value2, err2 := cmd.RunWithValueError(ctx) t.AssertNil(err2) - t.Assert(value2, `{"Content":"tom"}`) + t.Assert(value2, `{"Name":"tom","Version":false}`) + + // test name tag and orphan tag true + os.Args = []string{"root", "test", "-v"} + value3, err3 := cmd.RunWithValueError(ctx) + t.AssertNil(err3) + t.Assert(value3, `{"Name":"tom","Version":true}`) }) } @@ -123,7 +132,7 @@ func Test_Command_AddObject(t *testing.T) { os.Args = []string{"start", "root", "test", "-n=john"} value, err := command.RunWithValueError(ctx) t.AssertNil(err) - t.Assert(value, `{"Content":"john"}`) + t.Assert(value, `{"Name":"john","Version":false}`) }) } diff --git a/util/gconv/gconv_maptomaps.go b/util/gconv/gconv_maptomaps.go index 4a474ef8c..63d19759d 100644 --- a/util/gconv/gconv_maptomaps.go +++ b/util/gconv/gconv_maptomaps.go @@ -28,7 +28,7 @@ func MapToMaps(params interface{}, pointer interface{}, mapping ...map[string]st // // The optional parameter `mapping` is used for struct attribute to map key mapping, which makes // sense only if the item of `params` is type struct. -func doMapToMaps(params interface{}, pointer interface{}, mapping ...map[string]string) (err error) { +func doMapToMaps(params interface{}, pointer interface{}, paramKeyToAttrMap ...map[string]string) (err error) { // If given `params` is JSON, it then uses json.Unmarshal doing the converting. switch r := params.(type) { case []byte: @@ -124,13 +124,13 @@ func doMapToMaps(params interface{}, pointer interface{}, mapping ...map[string] var item reflect.Value if pointerElemType.Kind() == reflect.Ptr { item = reflect.New(pointerElemType.Elem()) - if err = MapToMap(paramsRv.Index(i).Interface(), item, mapping...); err != nil { + if err = MapToMap(paramsRv.Index(i).Interface(), item, paramKeyToAttrMap...); err != nil { return err } pointerSlice.Index(i).Set(item) } else { item = reflect.New(pointerElemType) - if err = MapToMap(paramsRv.Index(i).Interface(), item, mapping...); err != nil { + if err = MapToMap(paramsRv.Index(i).Interface(), item, paramKeyToAttrMap...); err != nil { return err } pointerSlice.Index(i).Set(item.Elem()) diff --git a/util/gconv/gconv_scan.go b/util/gconv/gconv_scan.go index 6187d079d..4f286ad89 100644 --- a/util/gconv/gconv_scan.go +++ b/util/gconv/gconv_scan.go @@ -23,7 +23,7 @@ import ( // It calls function `doMapToMaps` internally if `pointer` is type of *[]map/*[]*map for converting. // It calls function `doStruct` internally if `pointer` is type of *struct/**struct for converting. // It calls function `doStructs` internally if `pointer` is type of *[]struct/*[]*struct for converting. -func Scan(params interface{}, pointer interface{}, mapping ...map[string]string) (err error) { +func Scan(params interface{}, pointer interface{}, paramKeyToAttrMap ...map[string]string) (err error) { var ( pointerType reflect.Type pointerKind reflect.Kind @@ -82,12 +82,12 @@ func Scan(params interface{}, pointer interface{}, mapping ...map[string]string) pointerElemKind = pointerElem.Kind() keyToAttributeNameMapping map[string]string ) - if len(mapping) > 0 { - keyToAttributeNameMapping = mapping[0] + if len(paramKeyToAttrMap) > 0 { + keyToAttributeNameMapping = paramKeyToAttrMap[0] } switch pointerElemKind { case reflect.Map: - return doMapToMap(params, pointer, mapping...) + return doMapToMap(params, pointer, paramKeyToAttrMap...) case reflect.Array, reflect.Slice: var ( @@ -99,7 +99,7 @@ func Scan(params interface{}, pointer interface{}, mapping ...map[string]string) sliceElemKind = sliceElem.Kind() } if sliceElemKind == reflect.Map { - return doMapToMaps(params, pointer, mapping...) + return doMapToMaps(params, pointer, paramKeyToAttrMap...) } return doStructs(params, pointer, keyToAttributeNameMapping, "") diff --git a/util/gconv/gconv_struct.go b/util/gconv/gconv_struct.go index b3554ba55..44b268515 100644 --- a/util/gconv/gconv_struct.go +++ b/util/gconv/gconv_struct.go @@ -31,8 +31,8 @@ import ( // It will automatically convert the first letter of the key to uppercase // in mapping procedure to do the matching. // It ignores the map key, if it does not match. -func Struct(params interface{}, pointer interface{}, mapping ...map[string]string) (err error) { - return Scan(params, pointer, mapping...) +func Struct(params interface{}, pointer interface{}, paramKeyToAttrMap ...map[string]string) (err error) { + return Scan(params, pointer, paramKeyToAttrMap...) } // StructTag acts as Struct but also with support for priority tag feature, which retrieves the @@ -85,7 +85,7 @@ func doStructWithJsonCheck(params interface{}, pointer interface{}) (err error, } // doStruct is the core internal converting function for any data to struct. -func doStruct(params interface{}, pointer interface{}, mapping map[string]string, priorityTag string) (err error) { +func doStruct(params interface{}, pointer interface{}, paramKeyToAttrMap map[string]string, priorityTag string) (err error) { if params == nil { // If `params` is nil, no conversion. return nil @@ -252,7 +252,7 @@ func doStruct(params interface{}, pointer interface{}, mapping map[string]string continue } } - if err = doStruct(paramsMap, elemFieldValue, mapping, priorityTag); err != nil { + if err = doStruct(paramsMap, elemFieldValue, paramKeyToAttrMap, priorityTag); err != nil { return err } } else { @@ -264,7 +264,7 @@ func doStruct(params interface{}, pointer interface{}, mapping map[string]string return nil } - // The key of the tagMap is the attribute name of the struct, + // The key of the `attrToTagCheckNameMap` is the attribute name of the struct, // and the value is its replaced tag name for later comparison to improve performance. var ( attrToTagCheckNameMap = make(map[string]string) @@ -292,11 +292,27 @@ func doStruct(params interface{}, pointer interface{}, mapping map[string]string paramsMap[attributeName] = paramsMap[tagName] } } + + // To convert value base on custom parameter key to attribute name map. + err = doStructBaseOnParamKeyToAttrMap( + pointerElemReflectValue, + paramsMap, + paramKeyToAttrMap, + doneMap, + ) + if err != nil { + return err + } + // Already done all attributes value assignment nothing to do next. + if len(doneMap) == len(attrToCheckNameMap) { + return nil + } + // To convert value base on precise attribute name. err = doStructBaseOnAttribute( pointerElemReflectValue, paramsMap, - mapping, + paramKeyToAttrMap, doneMap, attrToCheckNameMap, ) @@ -307,11 +323,12 @@ func doStruct(params interface{}, pointer interface{}, mapping map[string]string if len(doneMap) == len(attrToCheckNameMap) { return nil } + // To convert value base on parameter map. err = doStructBaseOnParamMap( pointerElemReflectValue, paramsMap, - mapping, + paramKeyToAttrMap, doneMap, attrToCheckNameMap, attrToTagCheckNameMap, @@ -323,17 +340,47 @@ func doStruct(params interface{}, pointer interface{}, mapping map[string]string return nil } +func doStructBaseOnParamKeyToAttrMap( + pointerElemReflectValue reflect.Value, + paramsMap map[string]interface{}, + paramKeyToAttrMap map[string]string, + doneAttrMap map[string]struct{}, +) error { + if len(paramKeyToAttrMap) == 0 { + return nil + } + for paramKey, attrName := range paramKeyToAttrMap { + paramValue, ok := paramsMap[paramKey] + if !ok { + continue + } + // If the attribute name is already checked converting, then skip it. + if _, ok = doneAttrMap[attrName]; ok { + continue + } + // Mark it done. + doneAttrMap[attrName] = struct{}{} + if err := bindVarToStructAttr( + pointerElemReflectValue, attrName, paramValue, paramKeyToAttrMap, + ); err != nil { + return err + } + } + return nil +} + func doStructBaseOnAttribute( pointerElemReflectValue reflect.Value, paramsMap map[string]interface{}, - mapping map[string]string, - doneMap map[string]struct{}, + paramKeyToAttrMap map[string]string, + doneAttrMap map[string]struct{}, attrToCheckNameMap map[string]string, ) error { var customMappingAttrMap = make(map[string]struct{}) - if len(mapping) > 0 { + if len(paramKeyToAttrMap) > 0 { + // It ignores the attribute names if it is specified in the `paramKeyToAttrMap`. for paramName := range paramsMap { - if passedAttrKey, ok := mapping[paramName]; ok { + if passedAttrKey, ok := paramKeyToAttrMap[paramName]; ok { customMappingAttrMap[passedAttrKey] = struct{}{} } } @@ -344,17 +391,19 @@ func doStructBaseOnAttribute( if !ok { continue } - // If the attribute name is in custom mapping, it then ignores this converting. + // If the attribute name is in custom paramKeyToAttrMap, it then ignores this converting. if _, ok = customMappingAttrMap[attrName]; ok { continue } // If the attribute name is already checked converting, then skip it. - if _, ok = doneMap[attrName]; ok { + if _, ok = doneAttrMap[attrName]; ok { continue } // Mark it done. - doneMap[attrName] = struct{}{} - if err := bindVarToStructAttr(pointerElemReflectValue, attrName, paramValue, mapping); err != nil { + doneAttrMap[attrName] = struct{}{} + if err := bindVarToStructAttr( + pointerElemReflectValue, attrName, paramValue, paramKeyToAttrMap, + ); err != nil { return err } } @@ -364,8 +413,8 @@ func doStructBaseOnAttribute( func doStructBaseOnParamMap( pointerElemReflectValue reflect.Value, paramsMap map[string]interface{}, - mapping map[string]string, - doneMap map[string]struct{}, + paramKeyToAttrMap map[string]string, + doneAttrMap map[string]struct{}, attrToCheckNameMap map[string]string, attrToTagCheckNameMap map[string]string, tagToAttrNameMap map[string]string, @@ -375,45 +424,35 @@ func doStructBaseOnParamMap( checkName string ) for paramName, paramValue := range paramsMap { - attrName = "" - // It firstly checks the passed mapping rules. - if len(mapping) > 0 { - if passedAttrKey, ok := mapping[paramName]; ok { - attrName = passedAttrKey - } - } - // It secondly checks the predefined tags and matching rules. + // It firstly considers `paramName` as accurate tag name, + // and retrieve attribute name from `tagToAttrNameMap` . + attrName = tagToAttrNameMap[paramName] if attrName == "" { - // It firstly considers `paramName` as accurate tag name, - // and retrieve attribute name from `tagToAttrNameMap` . - attrName = tagToAttrNameMap[paramName] - if attrName == "" { - checkName = utils.RemoveSymbols(paramName) - // Loop to find the matched attribute name with or without - // string cases and chars like '-'/'_'/'.'/' '. + checkName = utils.RemoveSymbols(paramName) + // Loop to find the matched attribute name with or without + // string cases and chars like '-'/'_'/'.'/' '. - // Matching the parameters to struct tag names. - // The `attrKey` is the attribute name of the struct. - for attrKey, cmpKey := range attrToTagCheckNameMap { - if strings.EqualFold(checkName, cmpKey) { - attrName = attrKey - break - } + // Matching the parameters to struct tag names. + // The `attrKey` is the attribute name of the struct. + for attrKey, cmpKey := range attrToTagCheckNameMap { + if strings.EqualFold(checkName, cmpKey) { + attrName = attrKey + break } } + } - // Matching the parameters to struct attributes. - if attrName == "" { - for attrKey, cmpKey := range attrToCheckNameMap { - // Eg: - // UserName eq user_name - // User-Name eq username - // username eq userName - // etc. - if strings.EqualFold(checkName, cmpKey) { - attrName = attrKey - break - } + // Matching the parameters to struct attributes. + if attrName == "" { + for attrKey, cmpKey := range attrToCheckNameMap { + // Eg: + // UserName eq user_name + // User-Name eq username + // username eq userName + // etc. + if strings.EqualFold(checkName, cmpKey) { + attrName = attrKey + break } } } @@ -423,12 +462,14 @@ func doStructBaseOnParamMap( continue } // If the attribute name is already checked converting, then skip it. - if _, ok := doneMap[attrName]; ok { + if _, ok := doneAttrMap[attrName]; ok { continue } // Mark it done. - doneMap[attrName] = struct{}{} - if err := bindVarToStructAttr(pointerElemReflectValue, attrName, paramValue, mapping); err != nil { + doneAttrMap[attrName] = struct{}{} + if err := bindVarToStructAttr( + pointerElemReflectValue, attrName, paramValue, paramKeyToAttrMap, + ); err != nil { return err } } @@ -438,7 +479,7 @@ func doStructBaseOnParamMap( // bindVarToStructAttr sets value to struct object attribute by name. func bindVarToStructAttr( structReflectValue reflect.Value, - attrName string, value interface{}, mapping map[string]string, + attrName string, value interface{}, paramKeyToAttrMap map[string]string, ) (err error) { structFieldValue := structReflectValue.FieldByName(attrName) if !structFieldValue.IsValid() { @@ -450,7 +491,7 @@ func bindVarToStructAttr( } defer func() { if exception := recover(); exception != nil { - if err = bindVarToReflectValue(structFieldValue, value, mapping); err != nil { + if err = bindVarToReflectValue(structFieldValue, value, paramKeyToAttrMap); err != nil { err = gerror.Wrapf(err, `error binding value to attribute "%s"`, attrName) } } @@ -575,7 +616,9 @@ func bindVarToReflectValueWithInterfaceCheck(reflectValue reflect.Value, value i } // bindVarToReflectValue sets `value` to reflect value object `structFieldValue`. -func bindVarToReflectValue(structFieldValue reflect.Value, value interface{}, mapping map[string]string) (err error) { +func bindVarToReflectValue( + structFieldValue reflect.Value, value interface{}, paramKeyToAttrMap map[string]string, +) (err error) { // JSON content converting. err, ok := doStructWithJsonCheck(value, structFieldValue) if err != nil { @@ -600,7 +643,7 @@ func bindVarToReflectValue(structFieldValue reflect.Value, value interface{}, ma // Converting using reflection by kind. switch kind { case reflect.Map: - return doMapToMap(value, structFieldValue, mapping) + return doMapToMap(value, structFieldValue, paramKeyToAttrMap) case reflect.Struct: // Recursively converting for struct attribute. @@ -716,12 +759,12 @@ func bindVarToReflectValue(structFieldValue reflect.Value, value interface{}, ma return err } elem := item.Elem() - if err = bindVarToReflectValue(elem, value, mapping); err == nil { + if err = bindVarToReflectValue(elem, value, paramKeyToAttrMap); err == nil { structFieldValue.Set(elem.Addr()) } } else { // Not empty pointer, it assigns values to it. - return bindVarToReflectValue(structFieldValue.Elem(), value, mapping) + return bindVarToReflectValue(structFieldValue.Elem(), value, paramKeyToAttrMap) } // It mainly and specially handles the interface of nil value. diff --git a/util/gconv/gconv_structs.go b/util/gconv/gconv_structs.go index b8c04ff66..42ec26c3f 100644 --- a/util/gconv/gconv_structs.go +++ b/util/gconv/gconv_structs.go @@ -16,8 +16,8 @@ import ( // Structs converts any slice to given struct slice. // Also see Scan, Struct. -func Structs(params interface{}, pointer interface{}, mapping ...map[string]string) (err error) { - return Scan(params, pointer, mapping...) +func Structs(params interface{}, pointer interface{}, paramKeyToAttrMap ...map[string]string) (err error) { + return Scan(params, pointer, paramKeyToAttrMap...) } // StructsTag acts as Structs but also with support for priority tag feature, which retrieves the @@ -34,7 +34,9 @@ func StructsTag(params interface{}, pointer interface{}, priorityTag string) (er // The parameter `pointer` should be type of pointer to slice of struct. // Note that if `pointer` is a pointer to another pointer of type of slice of struct, // it will create the struct/pointer internally. -func doStructs(params interface{}, pointer interface{}, mapping map[string]string, priorityTag string) (err error) { +func doStructs( + params interface{}, pointer interface{}, paramKeyToAttrMap map[string]string, priorityTag string, +) (err error) { if params == nil { // If `params` is nil, no conversion. return nil @@ -133,7 +135,7 @@ func doStructs(params interface{}, pointer interface{}, mapping map[string]strin if !tempReflectValue.IsValid() { tempReflectValue = reflect.New(itemType.Elem()).Elem() } - if err = doStruct(paramsList[i], tempReflectValue, mapping, priorityTag); err != nil { + if err = doStruct(paramsList[i], tempReflectValue, paramKeyToAttrMap, priorityTag); err != nil { return err } reflectElemArray.Index(i).Set(tempReflectValue.Addr()) @@ -147,7 +149,7 @@ func doStructs(params interface{}, pointer interface{}, mapping map[string]strin } else { tempReflectValue = reflect.New(itemType).Elem() } - if err = doStruct(paramsList[i], tempReflectValue, mapping, priorityTag); err != nil { + if err = doStruct(paramsList[i], tempReflectValue, paramKeyToAttrMap, priorityTag); err != nil { return err } reflectElemArray.Index(i).Set(tempReflectValue) diff --git a/util/gconv/gconv_z_unit_scan_test.go b/util/gconv/gconv_z_unit_scan_test.go index f94bf3e1a..560d39461 100644 --- a/util/gconv/gconv_z_unit_scan_test.go +++ b/util/gconv/gconv_z_unit_scan_test.go @@ -17,6 +17,33 @@ import ( "github.com/gogf/gf/v2/util/gconv" ) +func Test_Scan_WithMapParameter(t *testing.T) { + type User struct { + Uid int + Name string + } + gtest.C(t, func(t *gtest.T) { + for i := 0; i < 100; i++ { + var ( + user = new(User) + params = g.Map{ + "uid": 1, + "myname": "john", + "name": "smith", + } + ) + err := gconv.Scan(params, user, g.MapStrStr{ + "myname": "Name", + }) + t.AssertNil(err) + t.Assert(user, &User{ + Uid: 1, + Name: "john", + }) + } + }) +} + func Test_Scan_StructStructs(t *testing.T) { type User struct { Uid int From 9aa872e7058999eec025883fe5939bccc9235b3c Mon Sep 17 00:00:00 2001 From: John Guo Date: Thu, 23 Nov 2023 18:59:04 +0800 Subject: [PATCH 22/22] improve map converting feature using `MapOption` for package `gconv` (#3170) --- container/gvar/gvar_map.go | 28 ++++++---- database/gdb/gdb_func.go | 4 +- util/gconv/gconv_map.go | 84 ++++++++++++++++++++--------- util/gconv/gconv_maps.go | 15 +++--- util/gconv/gconv_structs.go | 5 ++ util/gconv/gconv_z_unit_all_test.go | 4 +- util/gconv/gconv_z_unit_map_test.go | 49 ++++++++++++++++- 7 files changed, 139 insertions(+), 50 deletions(-) diff --git a/container/gvar/gvar_map.go b/container/gvar/gvar_map.go index 268d9f140..f56874d17 100644 --- a/container/gvar/gvar_map.go +++ b/container/gvar/gvar_map.go @@ -8,24 +8,27 @@ package gvar import "github.com/gogf/gf/v2/util/gconv" +// MapOption specifies the option for map converting. +type MapOption = gconv.MapOption + // Map converts and returns `v` as map[string]interface{}. -func (v *Var) Map(tags ...string) map[string]interface{} { - return gconv.Map(v.Val(), tags...) +func (v *Var) Map(option ...MapOption) map[string]interface{} { + return gconv.Map(v.Val(), option...) } // MapStrAny is like function Map, but implements the interface of MapStrAny. -func (v *Var) MapStrAny() map[string]interface{} { - return v.Map() +func (v *Var) MapStrAny(option ...MapOption) map[string]interface{} { + return v.Map(option...) } // MapStrStr converts and returns `v` as map[string]string. -func (v *Var) MapStrStr(tags ...string) map[string]string { - return gconv.MapStrStr(v.Val(), tags...) +func (v *Var) MapStrStr(option ...MapOption) map[string]string { + return gconv.MapStrStr(v.Val(), option...) } // MapStrVar converts and returns `v` as map[string]Var. -func (v *Var) MapStrVar(tags ...string) map[string]*Var { - m := v.Map(tags...) +func (v *Var) MapStrVar(option ...MapOption) map[string]*Var { + m := v.Map(option...) if len(m) > 0 { vMap := make(map[string]*Var, len(m)) for k, v := range m { @@ -37,16 +40,19 @@ func (v *Var) MapStrVar(tags ...string) map[string]*Var { } // MapDeep converts and returns `v` as map[string]interface{} recursively. +// Deprecated: used Map instead. func (v *Var) MapDeep(tags ...string) map[string]interface{} { return gconv.MapDeep(v.Val(), tags...) } // MapStrStrDeep converts and returns `v` as map[string]string recursively. +// Deprecated: used MapStrStr instead. func (v *Var) MapStrStrDeep(tags ...string) map[string]string { return gconv.MapStrStrDeep(v.Val(), tags...) } // MapStrVarDeep converts and returns `v` as map[string]*Var recursively. +// Deprecated: used MapStrVar instead. func (v *Var) MapStrVarDeep(tags ...string) map[string]*Var { m := v.MapDeep(tags...) if len(m) > 0 { @@ -61,12 +67,12 @@ func (v *Var) MapStrVarDeep(tags ...string) map[string]*Var { // Maps converts and returns `v` as map[string]string. // See gconv.Maps. -func (v *Var) Maps(tags ...string) []map[string]interface{} { - return gconv.Maps(v.Val(), tags...) +func (v *Var) Maps(option ...MapOption) []map[string]interface{} { + return gconv.Maps(v.Val(), option...) } // MapsDeep converts `value` to []map[string]interface{} recursively. -// See gconv.MapsDeep. +// Deprecated: used Maps instead. func (v *Var) MapsDeep(tags ...string) []map[string]interface{} { return gconv.MapsDeep(v.Val(), tags...) } diff --git a/database/gdb/gdb_func.go b/database/gdb/gdb_func.go index 28710a203..ec5850902 100644 --- a/database/gdb/gdb_func.go +++ b/database/gdb/gdb_func.go @@ -210,14 +210,14 @@ func GetInsertOperationByOption(option InsertOption) string { } func anyValueToMapBeforeToRecord(value interface{}) map[string]interface{} { - return gconv.Map(value, structTagPriority...) + return gconv.Map(value, gconv.MapOption{Tags: structTagPriority}) } // DataToMapDeep converts `value` to map type recursively(if attribute struct is embedded). // The parameter `value` should be type of *map/map/*struct/struct. // It supports embedded struct definition for struct. func DataToMapDeep(value interface{}) map[string]interface{} { - m := gconv.Map(value, structTagPriority...) + m := gconv.Map(value, gconv.MapOption{Tags: structTagPriority}) for k, v := range m { switch v.(type) { case time.Time, *time.Time, gtime.Time, *gtime.Time, gjson.Json, *gjson.Json: diff --git a/util/gconv/gconv_map.go b/util/gconv/gconv_map.go index f9a510eec..7627d6840 100644 --- a/util/gconv/gconv_map.go +++ b/util/gconv/gconv_map.go @@ -22,40 +22,57 @@ const ( recursiveTypeTrue recursiveType = "true" ) +// MapOption specifies the option for map converting. +type MapOption struct { + // Deep marks doing Map function recursively, which means if the attribute of given converting value + // is also a struct/*struct, it automatically calls Map function on this attribute converting it to + // a map[string]interface{} type variable. + Deep bool + + // OmitEmpty ignores the attributes that has json omitempty tag. + OmitEmpty bool + + // Tags specifies the converted map key name by struct tag name. + Tags []string +} + // Map converts any variable `value` to map[string]interface{}. If the parameter `value` is not a // map/struct/*struct type, then the conversion will fail and returns nil. // // If `value` is a struct/*struct object, the second parameter `tags` specifies the most priority // tags that will be detected, otherwise it detects the tags in order of: // gconv, json, field name. -func Map(value interface{}, tags ...string) map[string]interface{} { - return doMapConvert(value, recursiveTypeAuto, false, tags...) +func Map(value interface{}, option ...MapOption) map[string]interface{} { + return doMapConvert(value, recursiveTypeAuto, false, option...) } // MapDeep does Map function recursively, which means if the attribute of `value` // is also a struct/*struct, calls Map function on this attribute converting it to // a map[string]interface{} type variable. -// Also see Map. +// Deprecated: used Map instead. func MapDeep(value interface{}, tags ...string) map[string]interface{} { - return doMapConvert(value, recursiveTypeTrue, false, tags...) + return doMapConvert(value, recursiveTypeTrue, false, MapOption{ + Tags: tags, + }) } // doMapConvert implements the map converting. // It automatically checks and converts json string to map if `value` is string/[]byte. // // TODO completely implement the recursive converting for all types, especially the map. -func doMapConvert(value interface{}, recursive recursiveType, mustMapReturn bool, tags ...string) map[string]interface{} { +func doMapConvert(value interface{}, recursive recursiveType, mustMapReturn bool, option ...MapOption) map[string]interface{} { if value == nil { return nil } + var usedOption = getUsedMapOption(option...) newTags := StructTagPriority - switch len(tags) { + switch len(usedOption.Tags) { case 0: // No need handling. case 1: - newTags = append(strings.Split(tags[0], ","), StructTagPriority...) + newTags = append(strings.Split(usedOption.Tags[0], ","), StructTagPriority...) default: - newTags = append(tags, StructTagPriority...) + newTags = append(usedOption.Tags, StructTagPriority...) } // Assert the common combination of types, and finally it uses reflection. dataMap := make(map[string]interface{}) @@ -79,6 +96,8 @@ func doMapConvert(value interface{}, recursive recursiveType, mustMapReturn bool return nil } case map[interface{}]interface{}: + recursiveOption := usedOption + recursiveOption.Tags = newTags for k, v := range r { dataMap[String(k)] = doMapConvertForMapOrStructValue( doMapConvertForMapOrStructValueInput{ @@ -86,7 +105,7 @@ func doMapConvert(value interface{}, recursive recursiveType, mustMapReturn bool Value: v, RecursiveType: recursive, RecursiveOption: recursive == recursiveTypeTrue, - Tags: newTags, + Option: recursiveOption, }, ) } @@ -136,6 +155,8 @@ func doMapConvert(value interface{}, recursive recursiveType, mustMapReturn bool } case map[string]interface{}: if recursive == recursiveTypeTrue { + recursiveOption := usedOption + recursiveOption.Tags = newTags // A copy of current map. for k, v := range r { dataMap[k] = doMapConvertForMapOrStructValue( @@ -144,7 +165,7 @@ func doMapConvert(value interface{}, recursive recursiveType, mustMapReturn bool Value: v, RecursiveType: recursive, RecursiveOption: recursive == recursiveTypeTrue, - Tags: newTags, + Option: recursiveOption, }, ) } @@ -153,6 +174,8 @@ func doMapConvert(value interface{}, recursive recursiveType, mustMapReturn bool return r } case map[int]interface{}: + recursiveOption := usedOption + recursiveOption.Tags = newTags for k, v := range r { dataMap[String(k)] = doMapConvertForMapOrStructValue( doMapConvertForMapOrStructValueInput{ @@ -160,7 +183,7 @@ func doMapConvert(value interface{}, recursive recursiveType, mustMapReturn bool Value: v, RecursiveType: recursive, RecursiveOption: recursive == recursiveTypeTrue, - Tags: newTags, + Option: recursiveOption, }, ) } @@ -202,13 +225,15 @@ func doMapConvert(value interface{}, recursive recursiveType, mustMapReturn bool } } case reflect.Map, reflect.Struct, reflect.Interface: + recursiveOption := usedOption + recursiveOption.Tags = newTags convertedValue := doMapConvertForMapOrStructValue( doMapConvertForMapOrStructValueInput{ IsRoot: true, Value: value, RecursiveType: recursive, RecursiveOption: recursive == recursiveTypeTrue, - Tags: newTags, + Option: recursiveOption, MustMapReturn: mustMapReturn, }, ) @@ -223,12 +248,20 @@ func doMapConvert(value interface{}, recursive recursiveType, mustMapReturn bool return dataMap } +func getUsedMapOption(option ...MapOption) MapOption { + var usedOption MapOption + if len(option) > 0 { + usedOption = option[0] + } + return usedOption +} + type doMapConvertForMapOrStructValueInput struct { IsRoot bool // It returns directly if it is not root and with no recursive converting. Value interface{} // Current operation value. RecursiveType recursiveType // The type from top function entry. RecursiveOption bool // Whether convert recursively for `current` operation. - Tags []string // Map key mapping. + Option MapOption // Map converting option. MustMapReturn bool // Must return map instead of Value when empty. } @@ -280,7 +313,7 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in Value: mapValue, RecursiveType: in.RecursiveType, RecursiveOption: in.RecursiveType == recursiveTypeTrue, - Tags: in.Tags, + Option: in.Option, }, ) } @@ -299,7 +332,7 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in Value: mapV, RecursiveType: in.RecursiveType, RecursiveOption: in.RecursiveType == recursiveTypeTrue, - Tags: in.Tags, + Option: in.Option, }, ) } else { @@ -327,7 +360,7 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in } mapKey = "" fieldTag := rtField.Tag - for _, tag := range in.Tags { + for _, tag := range in.Option.Tags { if mapKey = fieldTag.Get(tag); mapKey != "" { break } @@ -344,7 +377,7 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in if len(array) > 1 { switch strings.TrimSpace(array[1]) { case "omitempty": - if empty.IsEmpty(rvField.Interface()) { + if in.Option.OmitEmpty && empty.IsEmpty(rvField.Interface()) { continue } else { mapKey = strings.TrimSpace(array[0]) @@ -389,7 +422,7 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in Value: rvInterface, RecursiveType: in.RecursiveType, RecursiveOption: true, - Tags: in.Tags, + Option: in.Option, }) if m, ok := anonymousValue.(map[string]interface{}); ok { for k, v := range m { @@ -406,7 +439,7 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in Value: rvInterface, RecursiveType: in.RecursiveType, RecursiveOption: true, - Tags: in.Tags, + Option: in.Option, }) default: @@ -415,7 +448,7 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in Value: rvInterface, RecursiveType: in.RecursiveType, RecursiveOption: in.RecursiveType == recursiveTypeTrue, - Tags: in.Tags, + Option: in.Option, }) } @@ -434,7 +467,7 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in Value: rvAttrField.Index(arrayIndex).Interface(), RecursiveType: in.RecursiveType, RecursiveOption: in.RecursiveType == recursiveTypeTrue, - Tags: in.Tags, + Option: in.Option, }, ) } @@ -451,7 +484,7 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in Value: rvAttrField.MapIndex(k).Interface(), RecursiveType: in.RecursiveType, RecursiveOption: in.RecursiveType == recursiveTypeTrue, - Tags: in.Tags, + Option: in.Option, }, ) } @@ -490,7 +523,7 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in Value: reflectValue.Index(i).Interface(), RecursiveType: in.RecursiveType, RecursiveOption: in.RecursiveType == recursiveTypeTrue, - Tags: in.Tags, + Option: in.Option, }) } return array @@ -500,11 +533,11 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in // MapStrStr converts `value` to map[string]string. // Note that there might be data copy for this map type converting. -func MapStrStr(value interface{}, tags ...string) map[string]string { +func MapStrStr(value interface{}, option ...MapOption) map[string]string { if r, ok := value.(map[string]string); ok { return r } - m := Map(value, tags...) + m := Map(value, option...) if len(m) > 0 { vMap := make(map[string]string, len(m)) for k, v := range m { @@ -517,6 +550,7 @@ func MapStrStr(value interface{}, tags ...string) map[string]string { // MapStrStrDeep converts `value` to map[string]string recursively. // Note that there might be data copy for this map type converting. +// Deprecated: used MapStrStr instead. func MapStrStrDeep(value interface{}, tags ...string) map[string]string { if r, ok := value.(map[string]string); ok { return r diff --git a/util/gconv/gconv_maps.go b/util/gconv/gconv_maps.go index 3efe2386f..a68bb4e10 100644 --- a/util/gconv/gconv_maps.go +++ b/util/gconv/gconv_maps.go @@ -9,23 +9,19 @@ package gconv import "github.com/gogf/gf/v2/internal/json" // SliceMap is alias of Maps. -func SliceMap(any interface{}) []map[string]interface{} { - return Maps(any) +func SliceMap(any interface{}, option ...MapOption) []map[string]interface{} { + return Maps(any, option...) } // SliceMapDeep is alias of MapsDeep. +// Deprecated: used SliceMap instead. func SliceMapDeep(any interface{}) []map[string]interface{} { return MapsDeep(any) } -// SliceStruct is alias of Structs. -func SliceStruct(params interface{}, pointer interface{}, mapping ...map[string]string) (err error) { - return Structs(params, pointer, mapping...) -} - // Maps converts `value` to []map[string]interface{}. // Note that it automatically checks and converts json string to []map if `value` is string/[]byte. -func Maps(value interface{}, tags ...string) []map[string]interface{} { +func Maps(value interface{}, option ...MapOption) []map[string]interface{} { if value == nil { return nil } @@ -62,7 +58,7 @@ func Maps(value interface{}, tags ...string) []map[string]interface{} { } list := make([]map[string]interface{}, len(array)) for k, v := range array { - list[k] = Map(v, tags...) + list[k] = Map(v, option...) } return list } @@ -71,6 +67,7 @@ func Maps(value interface{}, tags ...string) []map[string]interface{} { // MapsDeep converts `value` to []map[string]interface{} recursively. // // TODO completely implement the recursive converting for all types. +// Deprecated: used Maps instead. func MapsDeep(value interface{}, tags ...string) []map[string]interface{} { if value == nil { return nil diff --git a/util/gconv/gconv_structs.go b/util/gconv/gconv_structs.go index 42ec26c3f..f8e93656c 100644 --- a/util/gconv/gconv_structs.go +++ b/util/gconv/gconv_structs.go @@ -20,6 +20,11 @@ func Structs(params interface{}, pointer interface{}, paramKeyToAttrMap ...map[s return Scan(params, pointer, paramKeyToAttrMap...) } +// SliceStruct is alias of Structs. +func SliceStruct(params interface{}, pointer interface{}, mapping ...map[string]string) (err error) { + return Structs(params, pointer, mapping...) +} + // StructsTag acts as Structs but also with support for priority tag feature, which retrieves the // specified tags for `params` key-value items to struct attribute names mapping. // The parameter `priorityTag` supports multiple tags that can be joined with char ','. diff --git a/util/gconv/gconv_z_unit_all_test.go b/util/gconv/gconv_z_unit_all_test.go index d6bc83e0f..78d62c054 100644 --- a/util/gconv/gconv_z_unit_all_test.go +++ b/util/gconv/gconv_z_unit_all_test.go @@ -946,8 +946,8 @@ func Test_Map_StructWithJsonTag_All(t *testing.T) { ssa: "222", } user2 := &user1 - _ = gconv.Map(user1, "Ss") - map1 := gconv.Map(user1, "json", "json2") + _ = gconv.Map(user1, gconv.MapOption{Tags: []string{"Ss"}}) + map1 := gconv.Map(user1, gconv.MapOption{Tags: []string{"json", "json2"}}) map2 := gconv.Map(user2) map3 := gconv.Map(user3) t.Assert(map1["Uid"], 100) diff --git a/util/gconv/gconv_z_unit_map_test.go b/util/gconv/gconv_z_unit_map_test.go index 9dca4ce39..b72a2eac4 100644 --- a/util/gconv/gconv_z_unit_map_test.go +++ b/util/gconv/gconv_z_unit_map_test.go @@ -617,6 +617,53 @@ func TestMapWithJsonOmitEmpty(t *testing.T) { Key: "", Value: 1, } - t.Assert(gconv.Map(s), g.Map{"Value": 1}) + m1 := gconv.Map(s) + t.Assert(m1, g.Map{ + "Key": "", + "Value": 1, + }) + + m2 := gconv.Map(s, gconv.MapOption{ + Deep: false, + OmitEmpty: true, + Tags: nil, + }) + t.Assert(m2, g.Map{ + "Value": 1, + }) + }) + + gtest.C(t, func(t *gtest.T) { + type ProductConfig struct { + Pid int `v:"required" json:"pid,omitempty"` + TimeSpan int `v:"required" json:"timeSpan,omitempty"` + } + type CreateGoodsDetail struct { + ProductConfig + AutoRenewFlag int `v:"required" json:"autoRenewFlag"` + } + s := &CreateGoodsDetail{ + ProductConfig: ProductConfig{ + Pid: 1, + TimeSpan: 0, + }, + AutoRenewFlag: 0, + } + m1 := gconv.Map(s) + t.Assert(m1, g.Map{ + "pid": 1, + "timeSpan": 0, + "autoRenewFlag": 0, + }) + + m2 := gconv.Map(s, gconv.MapOption{ + Deep: false, + OmitEmpty: true, + Tags: nil, + }) + t.Assert(m2, g.Map{ + "pid": 1, + "autoRenewFlag": 0, + }) }) }