@@ -45,17 +45,18 @@ import (
4545 "google.golang.org/grpc/codes"
4646 "google.golang.org/grpc/metadata"
4747 "google.golang.org/grpc/status"
48+ "google.golang.org/protobuf/proto"
4849)
4950
5051func installTool (ctx context.Context , pm * packagemanager.PackageManager , tool * cores.ToolRelease , downloadCB rpc.DownloadProgressCB , taskCB rpc.TaskProgressCB ) error {
5152 pme , release := pm .NewExplorer ()
5253 defer release ()
5354
54- taskCB (& rpc.TaskProgress {Name : i18n .Tr ("Downloading missing tool %s" , tool )} )
55+ taskCB (rpc.TaskProgress_builder {Name : proto . String ( i18n .Tr ("Downloading missing tool %s" , tool ))}. Build () )
5556 if err := pme .DownloadToolRelease (ctx , tool , downloadCB ); err != nil {
5657 return errors .New (i18n .Tr ("downloading %[1]s tool: %[2]s" , tool , err ))
5758 }
58- taskCB (& rpc.TaskProgress {Completed : true } )
59+ taskCB (rpc.TaskProgress_builder {Completed : proto . Bool ( true )}. Build () )
5960 if err := pme .InstallTool (tool , taskCB , true ); err != nil {
6061 return errors .New (i18n .Tr ("installing %[1]s tool: %[2]s" , tool , err ))
6162 }
@@ -97,7 +98,7 @@ func (s *arduinoCoreServerImpl) Create(ctx context.Context, req *rpc.CreateReque
9798 if err != nil {
9899 return nil , err
99100 }
100- return & rpc.CreateResponse {Instance : inst }, nil
101+ return rpc.CreateResponse_builder {Instance : inst }. Build () , nil
101102}
102103
103104// InitStreamResponseToCallbackFunction returns a gRPC stream to be used in Init that sends
@@ -128,29 +129,23 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
128129 responseCallback = func (* rpc.InitResponse ) error { return nil }
129130 }
130131 responseError := func (st * status.Status ) {
131- responseCallback (& rpc.InitResponse {
132- Message : & rpc.InitResponse_Error {
133- Error : st .Proto (),
134- },
135- })
132+ responseCallback (rpc.InitResponse_builder {
133+ Error : st .Proto (),
134+ }.Build ())
136135 }
137136 taskCallback := func (msg * rpc.TaskProgress ) {
138- responseCallback (& rpc.InitResponse {
139- Message : & rpc.InitResponse_InitProgress {
140- InitProgress : & rpc.InitResponse_Progress {
141- TaskProgress : msg ,
142- },
143- },
144- })
137+ responseCallback (rpc.InitResponse_builder {
138+ InitProgress : rpc.InitResponse_Progress_builder {
139+ TaskProgress : msg ,
140+ }.Build (),
141+ }.Build ())
145142 }
146143 downloadCallback := func (msg * rpc.DownloadProgress ) {
147- responseCallback (& rpc.InitResponse {
148- Message : & rpc.InitResponse_InitProgress {
149- InitProgress : & rpc.InitResponse_Progress {
150- DownloadProgress : msg ,
151- },
152- },
153- })
144+ responseCallback (rpc.InitResponse_builder {
145+ InitProgress : rpc.InitResponse_Progress_builder {
146+ DownloadProgress : msg ,
147+ }.Build (),
148+ }.Build ())
154149 }
155150
156151 // Try to extract profile if specified
@@ -165,11 +160,9 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
165160 return err
166161 }
167162 profile = p
168- responseCallback (& rpc.InitResponse {
169- Message : & rpc.InitResponse_Profile {
170- Profile : profile .ToRpc (),
171- },
172- })
163+ responseCallback (rpc.InitResponse_builder {
164+ Profile : profile .ToRpc (),
165+ }.Build ())
173166 }
174167
175168 // Perform first-update of indexes if needed
@@ -369,38 +362,38 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
369362
370363 if ! libDir .IsDir () {
371364 // Download library
372- taskCallback (& rpc.TaskProgress {Name : i18n .Tr ("Downloading library %s" , libraryRef )} )
365+ taskCallback (rpc.TaskProgress_builder {Name : proto . String ( i18n .Tr ("Downloading library %s" , libraryRef ))}. Build () )
373366 libRelease , err := li .FindRelease (libraryRef .Library , libraryRef .Version )
374367 if err != nil {
375- taskCallback (& rpc.TaskProgress {Name : i18n .Tr ("Library %s not found" , libraryRef )} )
368+ taskCallback (rpc.TaskProgress_builder {Name : proto . String ( i18n .Tr ("Library %s not found" , libraryRef ))}. Build () )
376369 err := & cmderrors.LibraryNotFoundError {Library : libraryRef .Library }
377370 responseError (err .GRPCStatus ())
378371 continue
379372 }
380373 config , err := s .settings .DownloaderConfig ()
381374 if err != nil {
382- taskCallback (& rpc.TaskProgress {Name : i18n .Tr ("Error downloading library %s" , libraryRef )} )
375+ taskCallback (rpc.TaskProgress_builder {Name : proto . String ( i18n .Tr ("Error downloading library %s" , libraryRef ))}. Build () )
383376 e := & cmderrors.FailedLibraryInstallError {Cause : err }
384377 responseError (e .GRPCStatus ())
385378 continue
386379 }
387380 if err := libRelease .Resource .Download (ctx , pme .DownloadDir , config , libRelease .String (), downloadCallback , "" ); err != nil {
388- taskCallback (& rpc.TaskProgress {Name : i18n .Tr ("Error downloading library %s" , libraryRef )} )
381+ taskCallback (rpc.TaskProgress_builder {Name : proto . String ( i18n .Tr ("Error downloading library %s" , libraryRef ))}. Build () )
389382 e := & cmderrors.FailedLibraryInstallError {Cause : err }
390383 responseError (e .GRPCStatus ())
391384 continue
392385 }
393- taskCallback (& rpc.TaskProgress {Completed : true } )
386+ taskCallback (rpc.TaskProgress_builder {Completed : proto . Bool ( true )}. Build () )
394387
395388 // Install library
396- taskCallback (& rpc.TaskProgress {Name : i18n .Tr ("Installing library %s" , libraryRef )} )
389+ taskCallback (rpc.TaskProgress_builder {Name : proto . String ( i18n .Tr ("Installing library %s" , libraryRef ))}. Build () )
397390 if err := libRelease .Resource .Install (pme .DownloadDir , libRoot , libDir ); err != nil {
398- taskCallback (& rpc.TaskProgress {Name : i18n .Tr ("Error installing library %s" , libraryRef )} )
391+ taskCallback (rpc.TaskProgress_builder {Name : proto . String ( i18n .Tr ("Error installing library %s" , libraryRef ))}. Build () )
399392 e := & cmderrors.FailedLibraryInstallError {Cause : err }
400393 responseError (e .GRPCStatus ())
401394 continue
402395 }
403- taskCallback (& rpc.TaskProgress {Completed : true } )
396+ taskCallback (rpc.TaskProgress_builder {Completed : proto . Bool ( true )}. Build () )
404397 }
405398
406399 lmb .AddLibrariesDir (librariesmanager.LibrariesDir {
@@ -456,8 +449,7 @@ func UpdateLibrariesIndexStreamResponseToCallbackFunction(ctx context.Context, d
456449func (s * arduinoCoreServerImpl ) UpdateLibrariesIndex (req * rpc.UpdateLibrariesIndexRequest , stream rpc.ArduinoCoreService_UpdateLibrariesIndexServer ) error {
457450 syncSend := NewSynchronizedSend (stream .Send )
458451 downloadCB := func (p * rpc.DownloadProgress ) {
459- syncSend .Send (& rpc.UpdateLibrariesIndexResponse {
460- Message : & rpc.UpdateLibrariesIndexResponse_DownloadProgress {DownloadProgress : p }})
452+ syncSend .Send (rpc.UpdateLibrariesIndexResponse_builder {DownloadProgress : p }.Build ())
461453 }
462454
463455 pme , release , err := instances .GetPackageManagerExplorer (req .GetInstance ())
@@ -469,16 +461,14 @@ func (s *arduinoCoreServerImpl) UpdateLibrariesIndex(req *rpc.UpdateLibrariesInd
469461 index := globals .LibrariesIndexResource
470462
471463 resultCB := func (status rpc.IndexUpdateReport_Status ) {
472- syncSend .Send (& rpc.UpdateLibrariesIndexResponse {
473- Message : & rpc.UpdateLibrariesIndexResponse_Result_ {
474- Result : & rpc.UpdateLibrariesIndexResponse_Result {
475- LibrariesIndex : & rpc.IndexUpdateReport {
476- IndexUrl : index .URL .String (),
477- Status : status ,
478- },
479- },
480- },
481- })
464+ syncSend .Send (rpc.UpdateLibrariesIndexResponse_builder {
465+ Result : rpc.UpdateLibrariesIndexResponse_Result_builder {
466+ LibrariesIndex : rpc.IndexUpdateReport_builder {
467+ IndexUrl : proto .String (index .URL .String ()),
468+ Status : & status ,
469+ }.Build (),
470+ }.Build (),
471+ }.Build ())
482472 }
483473
484474 // Create the index directory if it doesn't exist
@@ -535,17 +525,15 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
535525 }
536526
537527 report := func (indexURL * url.URL , status rpc.IndexUpdateReport_Status ) * rpc.IndexUpdateReport {
538- return & rpc.IndexUpdateReport {
539- IndexUrl : indexURL .String (),
540- Status : status ,
541- }
528+ return rpc.IndexUpdateReport_builder {
529+ IndexUrl : proto . String ( indexURL .String () ),
530+ Status : & status ,
531+ }. Build ()
542532 }
543533
544534 syncSend := NewSynchronizedSend (stream .Send )
545535 var downloadCB rpc.DownloadProgressCB = func (p * rpc.DownloadProgress ) {
546- syncSend .Send (& rpc.UpdateIndexResponse {
547- Message : & rpc.UpdateIndexResponse_DownloadProgress {DownloadProgress : p },
548- })
536+ syncSend .Send (rpc.UpdateIndexResponse_builder {DownloadProgress : p }.Build ())
549537 }
550538 indexpath := s .settings .DataDir ()
551539
@@ -555,7 +543,7 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
555543 }
556544
557545 failed := false
558- result := & rpc.UpdateIndexResponse_Result {}
546+ result := rpc.UpdateIndexResponse_Result_builder {}
559547 for _ , u := range urls {
560548 URL , err := url .Parse (u )
561549 if err != nil {
@@ -564,7 +552,7 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
564552 downloadCB .Start (u , i18n .Tr ("Downloading index: %s" , u ))
565553 downloadCB .End (false , msg )
566554 failed = true
567- result .UpdatedIndexes = append (result .GetUpdatedIndexes () , report (URL , rpc .IndexUpdateReport_STATUS_FAILED ))
555+ result .UpdatedIndexes = append (result .UpdatedIndexes , report (URL , rpc .IndexUpdateReport_STATUS_FAILED ))
568556 continue
569557 }
570558
@@ -582,9 +570,9 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
582570 downloadCB .Start (u , i18n .Tr ("Downloading index: %s" , filepath .Base (URL .Path )))
583571 downloadCB .End (false , msg )
584572 failed = true
585- result .UpdatedIndexes = append (result .GetUpdatedIndexes () , report (URL , rpc .IndexUpdateReport_STATUS_FAILED ))
573+ result .UpdatedIndexes = append (result .UpdatedIndexes , report (URL , rpc .IndexUpdateReport_STATUS_FAILED ))
586574 } else {
587- result .UpdatedIndexes = append (result .GetUpdatedIndexes () , report (URL , rpc .IndexUpdateReport_STATUS_SKIPPED ))
575+ result .UpdatedIndexes = append (result .UpdatedIndexes , report (URL , rpc .IndexUpdateReport_STATUS_SKIPPED ))
588576 }
589577 continue
590578 }
@@ -596,14 +584,14 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
596584 downloadCB .Start (u , i18n .Tr ("Downloading index: %s" , filepath .Base (URL .Path )))
597585 downloadCB .End (false , i18n .Tr ("Invalid index URL: %s" , err ))
598586 failed = true
599- result .UpdatedIndexes = append (result .GetUpdatedIndexes () , report (URL , rpc .IndexUpdateReport_STATUS_FAILED ))
587+ result .UpdatedIndexes = append (result .UpdatedIndexes , report (URL , rpc .IndexUpdateReport_STATUS_FAILED ))
600588 continue
601589 }
602590 indexFile := indexpath .Join (indexFileName )
603591 if info , err := indexFile .Stat (); err == nil {
604592 ageSecs := int64 (time .Since (info .ModTime ()).Seconds ())
605593 if ageSecs < req .GetUpdateIfOlderThanSecs () {
606- result .UpdatedIndexes = append (result .GetUpdatedIndexes () , report (URL , rpc .IndexUpdateReport_STATUS_ALREADY_UP_TO_DATE ))
594+ result .UpdatedIndexes = append (result .UpdatedIndexes , report (URL , rpc .IndexUpdateReport_STATUS_ALREADY_UP_TO_DATE ))
607595 continue
608596 }
609597 }
@@ -622,14 +610,14 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
622610 }
623611 if err := indexResource .Download (stream .Context (), indexpath , downloadCB , config ); err != nil {
624612 failed = true
625- result .UpdatedIndexes = append (result .GetUpdatedIndexes () , report (URL , rpc .IndexUpdateReport_STATUS_FAILED ))
613+ result .UpdatedIndexes = append (result .UpdatedIndexes , report (URL , rpc .IndexUpdateReport_STATUS_FAILED ))
626614 } else {
627- result .UpdatedIndexes = append (result .GetUpdatedIndexes () , report (URL , rpc .IndexUpdateReport_STATUS_UPDATED ))
615+ result .UpdatedIndexes = append (result .UpdatedIndexes , report (URL , rpc .IndexUpdateReport_STATUS_UPDATED ))
628616 }
629617 }
630- syncSend .Send (& rpc.UpdateIndexResponse {
631- Message : & rpc. UpdateIndexResponse_Result_ { Result : result } ,
632- })
618+ syncSend .Send (rpc.UpdateIndexResponse_builder {
619+ Result : result . Build () ,
620+ }. Build () )
633621 if failed {
634622 return & cmderrors.FailedDownloadError {Message : i18n .Tr ("Some indexes could not be updated." )}
635623 }
@@ -644,7 +632,7 @@ func firstUpdate(ctx context.Context, srv rpc.ArduinoCoreServiceServer, instance
644632 if libraryIndex .NotExist () {
645633 // The library_index.json file doesn't exists, that means the CLI is run for the first time
646634 // so we proceed with the first update that downloads the file
647- req := & rpc.UpdateLibrariesIndexRequest {Instance : instance }
635+ req := rpc.UpdateLibrariesIndexRequest_builder {Instance : instance }. Build ()
648636 stream , _ := UpdateLibrariesIndexStreamResponseToCallbackFunction (ctx , downloadCb )
649637 if err := srv .UpdateLibrariesIndex (req , stream ); err != nil {
650638 return err
@@ -667,7 +655,7 @@ func firstUpdate(ctx context.Context, srv rpc.ArduinoCoreServiceServer, instance
667655 // or the 3rd party package index URL has just been added. Similarly to the
668656 // library update we download that file and all the other package indexes from
669657 // additional_urls
670- req := & rpc.UpdateIndexRequest {Instance : instance }
658+ req := rpc.UpdateIndexRequest_builder {Instance : instance }. Build ()
671659 stream , _ := UpdateIndexStreamResponseToCallbackFunction (ctx , downloadCb )
672660 if err := srv .UpdateIndex (req , stream ); err != nil {
673661 return err
0 commit comments