Skip to content

Commit

Permalink
fix: ent api proto generating bug in type
Browse files Browse the repository at this point in the history
  • Loading branch information
suyuan32 committed Jan 11, 2023
1 parent feaa665 commit fb016cd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
6 changes: 1 addition & 5 deletions tools/goctl/api/gogen/makefile.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,4 @@ gen-swagger:
serve-swagger:
lsof -i:36666 | awk 'NR!=1 {print $2}' | xargs killall -9 || true
@printf $(GREEN)"[SUCCESS] serve swagger-ui successfully"
swagger serve -F=swagger --port 36666 {{.serviceName}}.yml

gen-api-proto-logic:
goctls api proto --proto=$(proto) --style=go_zero --multiple=false --service_name={{.serviceName}} --search_key_num=3 --o=./ --model=$(model)
@printf $(GREEN)"[SUCCESS] generate ent logic codes successfully"
swagger serve -F=swagger --port 36666 {{.serviceName}}.yml
8 changes: 4 additions & 4 deletions tools/goctl/api/gogen/proto/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func GenLogicByProto(p *GenLogicByProtoContext) error {
}

// generate api file
apiData, err := GenApiData(p, &protoData, projectCtx)
apiData, err := GenApiData(p, &protoData)
if err != nil {
return err
}
Expand Down Expand Up @@ -249,7 +249,7 @@ func GenCRUDData(ctx *GenLogicByProtoContext, p *parser.Proto, projectCtx *ctx.P
return data
}

func GenApiData(ctx *GenLogicByProtoContext, p *parser.Proto, projectCtx *ctx.ProjectContext) (string, error) {
func GenApiData(ctx *GenLogicByProtoContext, p *parser.Proto) (string, error) {
infoData := strings.Builder{}
listData := strings.Builder{}
count := 0
Expand All @@ -265,10 +265,10 @@ func GenApiData(ctx *GenLogicByProtoContext, p *parser.Proto, projectCtx *ctx.Pr
}
var structData string

structData += fmt.Sprintf("\n\n\t\t// %s\n\t\t%s %s `json:\"%s\"`",
structData = fmt.Sprintf("\n\n\t\t// %s\n\t\t%s %s `json:\"%s\"`",
parser.CamelCase(protoField.Name),
parser.CamelCase(protoField.Name),
protoField.Type,
entx.ConvertProtoTypeToGoType(protoField.Type),
strcase.ToLowerCamel(protoField.Name))

infoData.WriteString(structData)
Expand Down
11 changes: 0 additions & 11 deletions tools/goctl/api/gogen/proto/utils.go

This file was deleted.

11 changes: 11 additions & 0 deletions tools/goctl/util/entx/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ func ConvertEntTypeToProtoType(typeName string) string {
return typeName
}

// ConvertProtoTypeToGoType returns go type from proto type
func ConvertProtoTypeToGoType(typeName string) string {
switch typeName {
case "float":
typeName = "float32"
case "double":
typeName = "float64"
}
return typeName
}

// ConvertSpecificNounToUpper is used to convert snack format to Ent format
func ConvertSpecificNounToUpper(str string) string {
target := parser.CamelCase(str)
Expand Down

0 comments on commit fb016cd

Please sign in to comment.