|
33 | 33 |
|
34 | 34 | // googleProtobufType returns the Go package type for a given Google Protobuf type. |
35 | 35 | // |
36 | | -//nolint:gocyclo // This function uses a large switch statement for type mapping, which is expected. |
| 36 | +//nolint:gocyclo,funlen // This function uses a large switch statement for type mapping, which is expected. |
37 | 37 | func googleProtobufType(tpe string) (string, bool) { |
38 | 38 | switch tpe { |
39 | 39 | case "google.protobuf.Any": |
@@ -146,6 +146,7 @@ func googleProtobufType(tpe string) (string, bool) { |
146 | 146 | return "", false |
147 | 147 | } |
148 | 148 | } |
| 149 | + |
149 | 150 | // ServiceMethod represents a method in a proto service. |
150 | 151 | type ServiceMethod struct { |
151 | 152 | Name string |
@@ -212,8 +213,8 @@ func generateWrapper(ctx *gofr.Context, options ...FileType) (interface{}, error |
212 | 213 | protoPath := ctx.Param("proto") |
213 | 214 | if protoPath == "" { |
214 | 215 | ctx.Error(ErrNoProtoFile) |
215 | | - return nil, ErrNoProtoFile |
216 | | -} |
| 216 | + return nil, ErrNoProtoFile |
| 217 | + } |
217 | 218 |
|
218 | 219 | definition, err := parseProtoFile(ctx, protoPath) |
219 | 220 | if err != nil { |
@@ -253,9 +254,11 @@ func parseProtoFile(ctx *gofr.Context, protoPath string) (*proto.Proto, error) { |
253 | 254 | ctx.Errorf("Failed to open proto file: %v", err) |
254 | 255 | return nil, ErrOpeningProtoFile |
255 | 256 | } |
256 | | - parser := proto.NewParser(file) |
| 257 | + |
257 | 258 | defer func() { _ = file.Close() }() |
258 | 259 |
|
| 260 | + parser := proto.NewParser(file) |
| 261 | + |
259 | 262 | definition, err := parser.Parse() |
260 | 263 | if err != nil { |
261 | 264 | ctx.Errorf("Failed to parse proto file: %v", err) |
@@ -400,6 +403,7 @@ func generateGoFrClient(ctx *gofr.Context, data *WrapperData) string { |
400 | 403 | // getPackageAndProject extracts the package name and project path from the proto definition. |
401 | 404 | func getPackageAndProject(ctx *gofr.Context, definition *proto.Proto, protoPath string) (projectPath, packageName string) { |
402 | 405 | const goPackage = "go_package" |
| 406 | + |
403 | 407 | proto.Walk(definition, |
404 | 408 | proto.WithOption(func(opt *proto.Option) { |
405 | 409 | if opt.Name == goPackage { |
@@ -444,6 +448,7 @@ func getImports(ctx *gofr.Context, definition *proto.Proto, protoPath string) [] |
444 | 448 | imports = append(imports, googleImport) |
445 | 449 | } else { |
446 | 450 | lastIndex := strings.LastIndex(protoPath, "/") |
| 451 | + |
447 | 452 | newProto, err := parseProtoFile(ctx, protoPath[:lastIndex+1]+imported.Filename) |
448 | 453 | if err != nil { |
449 | 454 | ctx.Errorf("Failed to parse imported proto file %s: %v", imported.Filename, err) |
@@ -513,10 +518,12 @@ func getProperType(tpe string) string { |
513 | 518 | } else if strings.Contains(tpe, ".") { |
514 | 519 | lastIndex := strings.LastIndex(tpe, ".") |
515 | 520 | submoduleIndex := strings.LastIndex(tpe[:lastIndex], ".") |
| 521 | + |
516 | 522 | if submoduleIndex != -1 { |
517 | 523 | return fmt.Sprintf("%s.%s", tpe[submoduleIndex+1:lastIndex], tpe[lastIndex+1:]) |
518 | 524 | } |
519 | 525 | } |
| 526 | + |
520 | 527 | return tpe |
521 | 528 | } |
522 | 529 |
|
|
0 commit comments