Skip to content

Commit

Permalink
upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
abulo committed Sep 5, 2023
1 parent 22c455a commit 35b5c8c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 19 deletions.
2 changes: 1 addition & 1 deletion core/env/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

const (
ratelVersion = "v3.6.9"
ratelVersion = "v3.6.10"
)

var (
Expand Down
19 changes: 10 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -43,19 +43,19 @@ 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
go.etcd.io/etcd/client/v3 v3.5.9
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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions toolkit/api/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -346,7 +349,6 @@ func {{.Name}}(newCtx *gin.Context){
}
{{- end}}
// 执行服务
res, err := client.{{.Name}}(ctx, request)
if err != nil {
globalLogger.Logger.WithFields(logrus.Fields{
Expand Down
12 changes: 8 additions & 4 deletions toolkit/api/hertz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
34 changes: 33 additions & 1 deletion toolkit/base/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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":
Expand All @@ -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":
Expand All @@ -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":
Expand All @@ -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":
Expand All @@ -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":
Expand All @@ -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":
Expand All @@ -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":
Expand All @@ -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")
}
Expand Down

0 comments on commit 35b5c8c

Please sign in to comment.