@@ -45,17 +45,18 @@ import (
45
45
"google.golang.org/grpc/codes"
46
46
"google.golang.org/grpc/metadata"
47
47
"google.golang.org/grpc/status"
48
+ "google.golang.org/protobuf/proto"
48
49
)
49
50
50
51
func installTool (ctx context.Context , pm * packagemanager.PackageManager , tool * cores.ToolRelease , downloadCB rpc.DownloadProgressCB , taskCB rpc.TaskProgressCB ) error {
51
52
pme , release := pm .NewExplorer ()
52
53
defer release ()
53
54
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 () )
55
56
if err := pme .DownloadToolRelease (ctx , tool , downloadCB ); err != nil {
56
57
return errors .New (i18n .Tr ("downloading %[1]s tool: %[2]s" , tool , err ))
57
58
}
58
- taskCB (& rpc.TaskProgress {Completed : true } )
59
+ taskCB (rpc.TaskProgress_builder {Completed : proto . Bool ( true )}. Build () )
59
60
if err := pme .InstallTool (tool , taskCB , true ); err != nil {
60
61
return errors .New (i18n .Tr ("installing %[1]s tool: %[2]s" , tool , err ))
61
62
}
@@ -97,7 +98,7 @@ func (s *arduinoCoreServerImpl) Create(ctx context.Context, req *rpc.CreateReque
97
98
if err != nil {
98
99
return nil , err
99
100
}
100
- return & rpc.CreateResponse {Instance : inst }, nil
101
+ return rpc.CreateResponse_builder {Instance : inst }. Build () , nil
101
102
}
102
103
103
104
// 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
128
129
responseCallback = func (* rpc.InitResponse ) error { return nil }
129
130
}
130
131
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 ())
136
135
}
137
136
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 ())
145
142
}
146
143
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 ())
154
149
}
155
150
156
151
// Try to extract profile if specified
@@ -165,11 +160,9 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
165
160
return err
166
161
}
167
162
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 ())
173
166
}
174
167
175
168
// Perform first-update of indexes if needed
@@ -369,38 +362,38 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
369
362
370
363
if ! libDir .IsDir () {
371
364
// 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 () )
373
366
libRelease , err := li .FindRelease (libraryRef .Library , libraryRef .Version )
374
367
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 () )
376
369
err := & cmderrors.LibraryNotFoundError {Library : libraryRef .Library }
377
370
responseError (err .GRPCStatus ())
378
371
continue
379
372
}
380
373
config , err := s .settings .DownloaderConfig ()
381
374
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 () )
383
376
e := & cmderrors.FailedLibraryInstallError {Cause : err }
384
377
responseError (e .GRPCStatus ())
385
378
continue
386
379
}
387
380
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 () )
389
382
e := & cmderrors.FailedLibraryInstallError {Cause : err }
390
383
responseError (e .GRPCStatus ())
391
384
continue
392
385
}
393
- taskCallback (& rpc.TaskProgress {Completed : true } )
386
+ taskCallback (rpc.TaskProgress_builder {Completed : proto . Bool ( true )}. Build () )
394
387
395
388
// 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 () )
397
390
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 () )
399
392
e := & cmderrors.FailedLibraryInstallError {Cause : err }
400
393
responseError (e .GRPCStatus ())
401
394
continue
402
395
}
403
- taskCallback (& rpc.TaskProgress {Completed : true } )
396
+ taskCallback (rpc.TaskProgress_builder {Completed : proto . Bool ( true )}. Build () )
404
397
}
405
398
406
399
lmb .AddLibrariesDir (librariesmanager.LibrariesDir {
@@ -456,8 +449,7 @@ func UpdateLibrariesIndexStreamResponseToCallbackFunction(ctx context.Context, d
456
449
func (s * arduinoCoreServerImpl ) UpdateLibrariesIndex (req * rpc.UpdateLibrariesIndexRequest , stream rpc.ArduinoCoreService_UpdateLibrariesIndexServer ) error {
457
450
syncSend := NewSynchronizedSend (stream .Send )
458
451
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 ())
461
453
}
462
454
463
455
pme , release , err := instances .GetPackageManagerExplorer (req .GetInstance ())
@@ -469,16 +461,14 @@ func (s *arduinoCoreServerImpl) UpdateLibrariesIndex(req *rpc.UpdateLibrariesInd
469
461
index := globals .LibrariesIndexResource
470
462
471
463
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 ())
482
472
}
483
473
484
474
// Create the index directory if it doesn't exist
@@ -535,17 +525,15 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
535
525
}
536
526
537
527
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 ()
542
532
}
543
533
544
534
syncSend := NewSynchronizedSend (stream .Send )
545
535
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 ())
549
537
}
550
538
indexpath := s .settings .DataDir ()
551
539
@@ -555,7 +543,7 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
555
543
}
556
544
557
545
failed := false
558
- result := & rpc.UpdateIndexResponse_Result {}
546
+ result := rpc.UpdateIndexResponse_Result_builder {}
559
547
for _ , u := range urls {
560
548
URL , err := url .Parse (u )
561
549
if err != nil {
@@ -564,7 +552,7 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
564
552
downloadCB .Start (u , i18n .Tr ("Downloading index: %s" , u ))
565
553
downloadCB .End (false , msg )
566
554
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 ))
568
556
continue
569
557
}
570
558
@@ -582,9 +570,9 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
582
570
downloadCB .Start (u , i18n .Tr ("Downloading index: %s" , filepath .Base (URL .Path )))
583
571
downloadCB .End (false , msg )
584
572
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 ))
586
574
} 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 ))
588
576
}
589
577
continue
590
578
}
@@ -596,14 +584,14 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
596
584
downloadCB .Start (u , i18n .Tr ("Downloading index: %s" , filepath .Base (URL .Path )))
597
585
downloadCB .End (false , i18n .Tr ("Invalid index URL: %s" , err ))
598
586
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 ))
600
588
continue
601
589
}
602
590
indexFile := indexpath .Join (indexFileName )
603
591
if info , err := indexFile .Stat (); err == nil {
604
592
ageSecs := int64 (time .Since (info .ModTime ()).Seconds ())
605
593
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 ))
607
595
continue
608
596
}
609
597
}
@@ -622,14 +610,14 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
622
610
}
623
611
if err := indexResource .Download (stream .Context (), indexpath , downloadCB , config ); err != nil {
624
612
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 ))
626
614
} 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 ))
628
616
}
629
617
}
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 () )
633
621
if failed {
634
622
return & cmderrors.FailedDownloadError {Message : i18n .Tr ("Some indexes could not be updated." )}
635
623
}
@@ -644,7 +632,7 @@ func firstUpdate(ctx context.Context, srv rpc.ArduinoCoreServiceServer, instance
644
632
if libraryIndex .NotExist () {
645
633
// The library_index.json file doesn't exists, that means the CLI is run for the first time
646
634
// 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 ()
648
636
stream , _ := UpdateLibrariesIndexStreamResponseToCallbackFunction (ctx , downloadCb )
649
637
if err := srv .UpdateLibrariesIndex (req , stream ); err != nil {
650
638
return err
@@ -667,7 +655,7 @@ func firstUpdate(ctx context.Context, srv rpc.ArduinoCoreServiceServer, instance
667
655
// or the 3rd party package index URL has just been added. Similarly to the
668
656
// library update we download that file and all the other package indexes from
669
657
// additional_urls
670
- req := & rpc.UpdateIndexRequest {Instance : instance }
658
+ req := rpc.UpdateIndexRequest_builder {Instance : instance }. Build ()
671
659
stream , _ := UpdateIndexStreamResponseToCallbackFunction (ctx , downloadCb )
672
660
if err := srv .UpdateIndex (req , stream ); err != nil {
673
661
return err
0 commit comments