@@ -113,8 +113,11 @@ func main() {
113
113
// Before we can do anything with the CLI, an "instance" must be created.
114
114
// We keep a reference to the created instance because we will need it to
115
115
// run subsequent commands.
116
+ log .Println ("calling Create" )
117
+ instance := createInstance (client )
118
+
116
119
log .Println ("calling Init" )
117
- instance := initInstance (client )
120
+ initInstance (client , instance )
118
121
119
122
// We set up the proxy and then run the update to verify that the proxy settings are currently used
120
123
log .Println ("calling setProxy" )
@@ -129,6 +132,11 @@ func main() {
129
132
log .Println ("calling UpdateIndex" )
130
133
callUpdateIndex (client , instance )
131
134
135
+ // Indexes are not implicitly detected after an update
136
+ // so we must initialize again explicitly
137
+ log .Println ("calling Init" )
138
+ initInstance (client , instance )
139
+
132
140
// Let's search for a platform (also known as 'core') called 'samd'.
133
141
log .Println ("calling PlatformSearch(samd)" )
134
142
callPlatformSearch (client , instance )
@@ -198,6 +206,11 @@ func main() {
198
206
log .Println ("calling UpdateLibrariesIndex()" )
199
207
callUpdateLibraryIndex (client , instance )
200
208
209
+ // Indexes are not implicitly detected after an update
210
+ // so we must initialize again explicitly
211
+ log .Println ("calling Init" )
212
+ initInstance (client , instance )
213
+
201
214
// Download a library
202
215
log .
Println (
"calling LibraryDownload([email protected] )" )
203
216
callLibDownload (client , instance )
@@ -326,47 +339,46 @@ func callWrite(client settings.SettingsServiceClient) {
326
339
}
327
340
}
328
341
329
- func initInstance (client rpc.ArduinoCoreServiceClient ) * rpc.Instance {
330
- // The configuration for this example client only contains the path to
331
- // the data folder.
332
- initRespStream , err := client .Init (context .Background (), & rpc.InitRequest {})
342
+ func createInstance (client rpc.ArduinoCoreServiceClient ) * rpc.Instance {
343
+ res , err := client .Create (context .Background (), & rpc.CreateRequest {})
333
344
if err != nil {
334
345
log .Fatalf ("Error creating server instance: %s" , err )
346
+ }
347
+ return res .Instance
348
+ }
335
349
350
+ func initInstance (client rpc.ArduinoCoreServiceClient , instance * rpc.Instance ) {
351
+ stream , err := client .Init (context .Background (), & rpc.InitRequest {
352
+ Instance : instance ,
353
+ })
354
+ if err != nil {
355
+ log .Fatalf ("Error initializing server instance: %s" , err )
336
356
}
337
357
338
- var instance * rpc.Instance
339
- // Loop and consume the server stream until all the setup procedures are done.
340
358
for {
341
- initResp , err := initRespStream .Recv ()
342
- // The server is done.
359
+ res , err := stream .Recv ()
360
+ // Server has finished sending
343
361
if err == io .EOF {
344
362
break
345
363
}
346
364
347
- // There was an error.
348
365
if err != nil {
349
366
log .Fatalf ("Init error: %s" , err )
350
367
}
351
368
352
- // The server sent us a valid instance, let's print its ID.
353
- if initResp .GetInstance () != nil {
354
- instance = initResp .GetInstance ()
355
- log .Printf ("Got a new instance with ID: %v" , instance .GetId ())
356
- }
357
-
358
- // When a download is ongoing, log the progress
359
- if initResp .GetDownloadProgress () != nil {
360
- log .Printf ("DOWNLOAD: %s" , initResp .GetDownloadProgress ())
369
+ if status := res .GetError (); status != nil {
370
+ log .Printf ("Init error %s" , status .String ())
361
371
}
362
372
363
- // When an overall task is ongoing, log the progress
364
- if initResp .GetTaskProgress () != nil {
365
- log .Printf ("TASK: %s" , initResp .GetTaskProgress ())
373
+ if progress := res .GetInitProgress (); progress != nil {
374
+ if downloadProgress := progress .GetDownloadProgress (); downloadProgress != nil {
375
+ log .Printf ("DOWNLOAD: %s" , downloadProgress )
376
+ }
377
+ if taskProgress := progress .GetTaskProgress (); taskProgress != nil {
378
+ log .Printf ("TASK: %s" , taskProgress )
379
+ }
366
380
}
367
381
}
368
-
369
- return instance
370
382
}
371
383
372
384
func callUpdateIndex (client rpc.ArduinoCoreServiceClient , instance * rpc.Instance ) {
0 commit comments