diff --git a/core/env/const.go b/core/env/const.go index 096ce25..c33b4ac 100644 --- a/core/env/const.go +++ b/core/env/const.go @@ -12,7 +12,7 @@ import ( ) const ( - ratelVersion = "v3.6.9" + ratelVersion = "v3.6.10" ) var ( diff --git a/go.mod b/go.mod index 80708b3..7fca8fd 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,8 @@ require ( dario.cat/mergo v1.0.0 github.com/AlecAivazis/survey/v2 v2.3.7 github.com/BurntSushi/toml v1.3.2 - github.com/ClickHouse/clickhouse-go/v2 v2.13.2 - github.com/cloudwego/hertz v0.6.7 + github.com/ClickHouse/clickhouse-go/v2 v2.13.4 + github.com/cloudwego/hertz v0.6.8 github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 github.com/disintegration/imaging v1.6.2 github.com/fatih/color v1.15.0 @@ -24,7 +24,7 @@ require ( github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 github.com/h2non/bimg v1.1.9 github.com/hashicorp/hcl v1.0.0 - github.com/hashicorp/hcl/v2 v2.17.0 + github.com/hashicorp/hcl/v2 v2.18.0 github.com/issue9/term/v3 v3.2.1 github.com/jlaffaye/ftp v0.2.0 github.com/json-iterator/go v1.1.12 @@ -43,7 +43,7 @@ require ( github.com/spf13/cobra v1.7.0 github.com/streadway/amqp v1.1.0 github.com/stretchr/testify v1.8.4 - github.com/tdewolff/parse/v2 v2.6.7 + github.com/tdewolff/parse/v2 v2.6.8 github.com/uber/jaeger-client-go v2.30.0+incompatible github.com/yosuke-furukawa/json5 v0.1.1 go.etcd.io/etcd/api/v3 v3.5.9 @@ -51,11 +51,11 @@ require ( go.mongodb.org/mongo-driver v1.12.1 go.uber.org/multierr v1.11.0 golang.org/x/crypto v0.12.0 - golang.org/x/image v0.11.0 + golang.org/x/image v0.12.0 golang.org/x/mod v0.12.0 golang.org/x/sync v0.3.0 - golang.org/x/text v0.12.0 - google.golang.org/genproto/googleapis/rpc v0.0.0-20230821184602-ccc8af3d0e93 + golang.org/x/text v0.13.0 + google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d google.golang.org/grpc v1.57.0 google.golang.org/protobuf v1.31.0 gopkg.in/yaml.v2 v2.4.0 @@ -68,6 +68,7 @@ require ( github.com/agext/levenshtein v1.2.1 // indirect github.com/andybalholm/brotli v1.0.5 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect + github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bytedance/go-tagexpr/v2 v2.9.2 // indirect github.com/bytedance/gopkg v0.0.0-20220413063733-65bf48ffb3a7 // indirect @@ -136,8 +137,8 @@ require ( github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect github.com/zclconf/go-cty v1.13.0 // indirect go.etcd.io/etcd/client/pkg/v3 v3.5.9 // indirect - go.opentelemetry.io/otel v1.16.0 // indirect - go.opentelemetry.io/otel/trace v1.16.0 // indirect + go.opentelemetry.io/otel v1.17.0 // indirect + go.opentelemetry.io/otel/trace v1.17.0 // indirect go.uber.org/atomic v1.11.0 // indirect go.uber.org/zap v1.25.0 // indirect golang.org/x/arch v0.3.0 // indirect diff --git a/toolkit/api/gin.go b/toolkit/api/gin.go index 35aa7ae..3afffc8 100644 --- a/toolkit/api/gin.go +++ b/toolkit/api/gin.go @@ -279,7 +279,7 @@ func {{.Name}}(newCtx *gin.Context){ client := {{.Pkg}}.New{{CamelStr .Table.TableName}}ServiceClient(grpcClient) request := &{{.Pkg}}.{{.Name}}Request{} // 构造查询条件 - {{ApiToProto .Condition "request" "newCtx.GetQuery"}} + {{ApiToProto .Condition "request" "newCtx.GetQuery" false}} // 执行服务 ctx := newCtx.Request.Context() res, err := client.{{.Name}}(ctx, request) @@ -320,10 +320,13 @@ func {{.Name}}(newCtx *gin.Context){ client := {{.Pkg}}.New{{CamelStr .Table.TableName}}ServiceClient(grpcClient) request := &{{.Pkg}}.{{.Name}}Request{} // 构造查询条件 - {{ApiToProto .Condition "request" "newCtx.GetQuery"}} {{- if .Page}} requestTotal := &{{.Pkg}}.{{.Name}}TotalRequest{} - {{ApiToProto .Condition "requestTotal" "newCtx.GetQuery"}} + {{ApiToProto .Condition "request" "newCtx.GetQuery" true}} + {{- else}} + {{ApiToProto .Condition "request" "newCtx.GetQuery" false}} + {{- end}} + {{- if .Page}} // 执行服务,获取数据量 resTotal, err := client.{{.Name}}Total(ctx, requestTotal) if err != nil { @@ -346,7 +349,6 @@ func {{.Name}}(newCtx *gin.Context){ } {{- end}} // 执行服务 - res, err := client.{{.Name}}(ctx, request) if err != nil { globalLogger.Logger.WithFields(logrus.Fields{ diff --git a/toolkit/api/hertz.go b/toolkit/api/hertz.go index d0c8589..98481b2 100644 --- a/toolkit/api/hertz.go +++ b/toolkit/api/hertz.go @@ -274,7 +274,7 @@ func {{.Name}}(ctx context.Context, newCtx *app.RequestContext) { client := {{.Pkg}}.New{{CamelStr .Table.TableName}}ServiceClient(grpcClient) request := &{{.Pkg}}.{{.Name}}Request{} // 构造查询条件 - {{ApiToProto .Condition "request" "newCtx.GetQuery"}} + {{ApiToProto .Condition "request" "newCtx.GetQuery" false}} // 执行服务 res, err := client.{{.Name}}(ctx, request) if err != nil { @@ -311,12 +311,16 @@ func {{.Name}}(ctx context.Context,newCtx *app.RequestContext){ } //链接服务 client := {{.Pkg}}.New{{CamelStr .Table.TableName}}ServiceClient(grpcClient) - request := &{{.Pkg}}.{{.Name}}Request{} // 构造查询条件 - {{ApiToProto .Condition "request" "newCtx.GetQuery"}} + request := &{{.Pkg}}.{{.Name}}Request{} {{- if .Page}} requestTotal := &{{.Pkg}}.{{.Name}}TotalRequest{} - {{ApiToProto .Condition "requestTotal" "newCtx.GetQuery"}} + {{ApiToProto .Condition "request" "newCtx.GetQuery" true}} + {{- else}} + {{ApiToProto .Condition "request" "newCtx.GetQuery" false}} + {{- end}} + + {{- if .Page}} // 执行服务,获取数据量 resTotal, err := client.{{.Name}}Total(ctx, requestTotal) if err != nil { diff --git a/toolkit/base/util.go b/toolkit/base/util.go index 2f3665a..d0d2912 100644 --- a/toolkit/base/util.go +++ b/toolkit/base/util.go @@ -248,7 +248,7 @@ func ProtoRequest(condition []Column) string { return builder.String() } -func ApiToProto(Condition []Column, res, request string) string { +func ApiToProto(Condition []Column, res, request string, page bool) string { builder := strings.Builder{} builder.WriteString("\n") for _, item := range Condition { @@ -259,6 +259,10 @@ func ApiToProto(Condition []Column, res, request string) string { builder.WriteString("\n") builder.WriteString(fmt.Sprintf(" %s.%s = proto.Int32(cast.ToInt32(val)) // %s", res, CamelStr(item.ColumnName), item.ColumnComment)) builder.WriteString("\n") + if page { + builder.WriteString(fmt.Sprintf(" %sTotal.%s = proto.Int32(cast.ToInt32(val)) // %s", res, CamelStr(item.ColumnName), item.ColumnComment)) + builder.WriteString("\n") + } builder.WriteString(" }") builder.WriteString("\n") case "null.Int64": @@ -267,6 +271,10 @@ func ApiToProto(Condition []Column, res, request string) string { builder.WriteString("\n") builder.WriteString(fmt.Sprintf(" %s.%s = proto.Int64(cast.ToInt64(val)) // %s", res, CamelStr(item.ColumnName), item.ColumnComment)) builder.WriteString("\n") + if page { + builder.WriteString(fmt.Sprintf(" %sTotal.%s = proto.Int64(cast.ToInt64(val)) // %s", res, CamelStr(item.ColumnName), item.ColumnComment)) + builder.WriteString("\n") + } builder.WriteString(" }") builder.WriteString("\n") case "null.Float32": @@ -283,6 +291,10 @@ func ApiToProto(Condition []Column, res, request string) string { builder.WriteString("\n") builder.WriteString(fmt.Sprintf(" %s.%s = proto.Float64(cast.ToFloat64(val)) // %s", res, CamelStr(item.ColumnName), item.ColumnComment)) builder.WriteString("\n") + if page { + builder.WriteString(fmt.Sprintf(" %sTotal.%s = proto.Float64(cast.ToFloat64(val)) // %s", res, CamelStr(item.ColumnName), item.ColumnComment)) + builder.WriteString("\n") + } builder.WriteString(" }") builder.WriteString("\n") case "null.String": @@ -291,6 +303,10 @@ func ApiToProto(Condition []Column, res, request string) string { builder.WriteString("\n") builder.WriteString(fmt.Sprintf(" %s.%s = proto.String(val) // %s", res, CamelStr(item.ColumnName), item.ColumnComment)) builder.WriteString("\n") + if page { + builder.WriteString(fmt.Sprintf(" %sTotal.%s = proto.String(val) // %s", res, CamelStr(item.ColumnName), item.ColumnComment)) + builder.WriteString("\n") + } builder.WriteString(" }") builder.WriteString("\n") case "null.Bytes": @@ -305,6 +321,10 @@ func ApiToProto(Condition []Column, res, request string) string { builder.WriteString("\n") builder.WriteString(fmt.Sprintf(" %s.%s = cast.ToString(%s(\"%s\")) // %s", res, CamelStr(item.ColumnName), request, Helper(item.ColumnName), item.ColumnComment)) builder.WriteString("\n") + if page { + builder.WriteString(fmt.Sprintf(" %sTotal.%s = cast.ToString(%s(\"%s\")) // %s", res, CamelStr(item.ColumnName), request, Helper(item.ColumnName), item.ColumnComment)) + builder.WriteString("\n") + } builder.WriteString(" }") builder.WriteString("\n") case "null.Bool": @@ -313,6 +333,10 @@ func ApiToProto(Condition []Column, res, request string) string { builder.WriteString("\n") builder.WriteString(fmt.Sprintf(" %s.%s = cast.ToBool(%s(\"%s\")) // %s", res, CamelStr(item.ColumnName), request, Helper(item.ColumnName), item.ColumnComment)) builder.WriteString("\n") + if page { + builder.WriteString(fmt.Sprintf(" %sTotal.%s = cast.ToBool(%s(\"%s\")) // %s", res, CamelStr(item.ColumnName), request, Helper(item.ColumnName), item.ColumnComment)) + builder.WriteString("\n") + } builder.WriteString(" }") builder.WriteString("\n") case "null.CTime": @@ -327,6 +351,10 @@ func ApiToProto(Condition []Column, res, request string) string { builder.WriteString("\n") builder.WriteString(fmt.Sprintf(" %s.%s = timestamppb.New(cast.ToTime(%s(\"%s\"))) // %s", res, CamelStr(item.ColumnName), request, Helper(item.ColumnName), item.ColumnComment)) builder.WriteString("\n") + if page { + builder.WriteString(fmt.Sprintf(" %sTotal.%s = timestamppb.New(cast.ToTime(%s(\"%s\"))) // %s", res, CamelStr(item.ColumnName), request, Helper(item.ColumnName), item.ColumnComment)) + builder.WriteString("\n") + } builder.WriteString(" }") builder.WriteString("\n") case "null.DateTime": @@ -341,6 +369,10 @@ func ApiToProto(Condition []Column, res, request string) string { builder.WriteString("\n") builder.WriteString(fmt.Sprintf(" %s.%s = timestamppb.New(cast.ToTime(%s(\"%s\"))) // %s", res, CamelStr(item.ColumnName), request, Helper(item.ColumnName), item.ColumnComment)) builder.WriteString("\n") + if page { + builder.WriteString(fmt.Sprintf(" %sTotal.%s = timestamppb.New(cast.ToTime(%s(\"%s\"))) // %s", res, CamelStr(item.ColumnName), request, Helper(item.ColumnName), item.ColumnComment)) + builder.WriteString("\n") + } builder.WriteString(" }") builder.WriteString("\n") }