@@ -184,7 +184,7 @@ type FileType struct {
184184}
185185
186186// BuildGRPCGoFrClient generates gRPC client wrapper code based on a proto definition.
187- func BuildGRPCGoFrClient (ctx * gofr.Context ) (any , error ) {
187+ func BuildGRPCGoFrClient (ctx * gofr.Context ) (interface {} , error ) {
188188 gRPCClient := []FileType {
189189 {FileSuffix : clientFileSuffix , CodeGenerator : generateGoFrClient },
190190 {FileSuffix : clientHealthFile , CodeGenerator : generateGoFrClientHealth },
@@ -194,7 +194,7 @@ func BuildGRPCGoFrClient(ctx *gofr.Context) (any, error) {
194194}
195195
196196// BuildGRPCGoFrServer generates gRPC client and server code based on a proto definition.
197- func BuildGRPCGoFrServer (ctx * gofr.Context ) (any , error ) {
197+ func BuildGRPCGoFrServer (ctx * gofr.Context ) (interface {} , error ) {
198198 gRPCServer := []FileType {
199199 {FileSuffix : serverWrapperFileSuffix , CodeGenerator : generateGoFrServerWrapper },
200200 {FileSuffix : serverHealthFile , CodeGenerator : generateGoFrServerHealthWrapper },
@@ -208,40 +208,40 @@ func BuildGRPCGoFrServer(ctx *gofr.Context) (any, error) {
208208// generateWrapper executes the function for specified FileType to create GoFr integrated
209209// gRPC server/client files with the required services in proto file and
210210// specified suffix for every service specified in the proto file.
211- func generateWrapper (ctx * gofr.Context , options ... FileType ) (any , error ) {
211+ func generateWrapper (ctx * gofr.Context , options ... FileType ) (interface {} , error ) {
212212 protoPath := ctx .Param ("proto" )
213213 if protoPath == "" {
214214 ctx .Error (ErrNoProtoFile )
215215 return nil , ErrNoProtoFile
216216}
217217
218- definition , err := parseProtoFile (ctx , protoPath )
219- if err != nil {
220- ctx .Errorf ("Failed to parse proto file: %v" , err )
221- return nil , err
222- }
223-
224- imports := getImports (ctx , definition , protoPath )
225- projectPath , packageName := getPackageAndProject (ctx , definition , protoPath )
226- services := getServices (ctx , definition )
227- requests := getRequests (ctx , services )
228-
229- for _ , service := range services {
230- wrapperData := WrapperData {
231- Package : packageName ,
232- Service : service .Name ,
233- Methods : service .Methods ,
234- Requests : uniqueRequestTypes (ctx , service .Methods ),
235- Source : path .Base (protoPath ),
236- Imports : imports ,
218+ definition , err := parseProtoFile (ctx , protoPath )
219+ if err != nil {
220+ ctx .Errorf ("Failed to parse proto file: %v" , err )
221+ return nil , err
237222 }
238223
239- if err := generateFiles (ctx , projectPath , service .Name , & wrapperData , requests , options ... ); err != nil {
240- return nil , err
224+ imports := getImports (ctx , definition , protoPath )
225+ projectPath , packageName := getPackageAndProject (ctx , definition , protoPath )
226+ services := getServices (ctx , definition )
227+ requests := getRequests (ctx , services )
228+
229+ for _ , service := range services {
230+ wrapperData := WrapperData {
231+ Package : packageName ,
232+ Service : service .Name ,
233+ Methods : service .Methods ,
234+ Requests : uniqueRequestTypes (ctx , service .Methods ),
235+ Source : path .Base (protoPath ),
236+ Imports : imports ,
237+ }
238+
239+ if err := generateFiles (ctx , projectPath , service .Name , & wrapperData , requests , options ... ); err != nil {
240+ return nil , err
241+ }
241242 }
242- }
243243
244- ctx .Info ("Successfully generated all files for GoFr integrated gRPC servers/clients" )
244+ ctx .Info ("Successfully generated all files for GoFr integrated gRPC servers/clients" )
245245
246246 return "Successfully generated all files for GoFr integrated gRPC servers/clients" , nil
247247}
@@ -464,8 +464,8 @@ func getImports(ctx *gofr.Context, definition *proto.Proto, protoPath string) []
464464 }
465465
466466 lastPiece := strings .LastIndex (packageName , "." )
467- formattedImport := fmt .Sprintf ("%s \" %s \" " , packageName [lastPiece + 1 :], packageSource )
468- imports = append (imports , fmt . Sprintf ( "%q" , formattedImport ) )
467+ formattedImport := fmt .Sprintf ("%s %q " , packageName [lastPiece + 1 :], packageSource )
468+ imports = append (imports , formattedImport )
469469 }
470470 }
471471
0 commit comments