Skip to content

Commit 6e387d9

Browse files
Run go fmt
1 parent 3810868 commit 6e387d9

File tree

7 files changed

+300
-297
lines changed

7 files changed

+300
-297
lines changed

rpc/cc/arduino/flasher/v1/commands.pb.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/cc/arduino/flasher/v1/commands_grpc.pb.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
1-
// This file is part of arduino-flasher-cli.
2-
//
3-
// Copyright 2025 ARDUINO SA (http://www.arduino.cc/)
4-
//
5-
// This software is released under the GNU General Public License version 3,
6-
// which covers the main part of arduino-flasher-cli.
7-
// The terms of this license can be found at:
8-
// https://www.gnu.org/licenses/gpl-3.0.en.html
9-
//
10-
// You can be released from the requirements of the above licenses by purchasing
11-
// a commercial license. Buying such a license is mandatory if you want to
12-
// modify or otherwise use the software for commercial activities involving the
13-
// Arduino software without disclosing the source code of your own applications.
14-
// To purchase a commercial license, send an email to [email protected].
15-
16-
package flasher
17-
18-
// DownloadProgressCB is a callback to get updates on download progress
19-
type DownloadProgressCB func(curr *DownloadProgress)
20-
21-
// Start sends a "start" DownloadProgress message to the callback function
22-
func (d DownloadProgressCB) Start(url, label string) {
23-
d(&DownloadProgress{
24-
Message: &DownloadProgress_Start{
25-
Start: &DownloadProgressStart{
26-
Url: url,
27-
Label: label,
28-
},
29-
},
30-
})
31-
}
32-
33-
// Update sends an "update" DownloadProgress message to the callback function
34-
func (d DownloadProgressCB) Update(downloaded int64, totalSize int64) {
35-
d(&DownloadProgress{
36-
Message: &DownloadProgress_Update{
37-
Update: &DownloadProgressUpdate{
38-
Downloaded: downloaded,
39-
TotalSize: totalSize,
40-
},
41-
},
42-
})
43-
}
44-
45-
// End sends an "end" DownloadProgress message to the callback function
46-
func (d DownloadProgressCB) End(success bool, message string) {
47-
d(&DownloadProgress{
48-
Message: &DownloadProgress_End{
49-
End: &DownloadProgressEnd{
50-
Success: success,
51-
Message: message,
52-
},
53-
},
54-
})
55-
}
56-
57-
// TaskProgressCB is a callback to receive progress messages
58-
type TaskProgressCB func(msg *TaskProgress)
1+
// This file is part of arduino-flasher-cli.
2+
//
3+
// Copyright 2025 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-flasher-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package flasher
17+
18+
// DownloadProgressCB is a callback to get updates on download progress
19+
type DownloadProgressCB func(curr *DownloadProgress)
20+
21+
// Start sends a "start" DownloadProgress message to the callback function
22+
func (d DownloadProgressCB) Start(url, label string) {
23+
d(&DownloadProgress{
24+
Message: &DownloadProgress_Start{
25+
Start: &DownloadProgressStart{
26+
Url: url,
27+
Label: label,
28+
},
29+
},
30+
})
31+
}
32+
33+
// Update sends an "update" DownloadProgress message to the callback function
34+
func (d DownloadProgressCB) Update(downloaded int64, totalSize int64) {
35+
d(&DownloadProgress{
36+
Message: &DownloadProgress_Update{
37+
Update: &DownloadProgressUpdate{
38+
Downloaded: downloaded,
39+
TotalSize: totalSize,
40+
},
41+
},
42+
})
43+
}
44+
45+
// End sends an "end" DownloadProgress message to the callback function
46+
func (d DownloadProgressCB) End(success bool, message string) {
47+
d(&DownloadProgress{
48+
Message: &DownloadProgress_End{
49+
End: &DownloadProgressEnd{
50+
Success: success,
51+
Message: message,
52+
},
53+
},
54+
})
55+
}
56+
57+
// TaskProgressCB is a callback to receive progress messages
58+
type TaskProgressCB func(msg *TaskProgress)

rpc/cc/arduino/flasher/v1/common.pb.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/service_download.go

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,70 @@
1-
// This file is part of arduino-flasher-cli.
2-
//
3-
// Copyright 2025 ARDUINO SA (http://www.arduino.cc/)
4-
//
5-
// This software is released under the GNU General Public License version 3,
6-
// which covers the main part of arduino-flasher-cli.
7-
// The terms of this license can be found at:
8-
// https://www.gnu.org/licenses/gpl-3.0.en.html
9-
//
10-
// You can be released from the requirements of the above licenses by purchasing
11-
// a commercial license. Buying such a license is mandatory if you want to
12-
// modify or otherwise use the software for commercial activities involving the
13-
// Arduino software without disclosing the source code of your own applications.
14-
// To purchase a commercial license, send an email to [email protected].
15-
16-
package service
17-
18-
import (
19-
"fmt"
20-
21-
"github.com/arduino/go-paths-helper"
22-
"go.bug.st/downloader/v2"
23-
24-
"github.com/arduino/arduino-flasher-cli/internal/updater"
25-
flasher "github.com/arduino/arduino-flasher-cli/rpc/cc/arduino/flasher/v1"
26-
)
27-
28-
func (s *flasherServerImpl) Download(req *flasher.DownloadRequest, stream flasher.Flasher_DownloadServer) error {
29-
syncSend := NewSynchronizedSend(stream.Send)
30-
ctx := stream.Context()
31-
downloadCB := func(p *flasher.DownloadProgress) {
32-
syncSend.Send(&flasher.DownloadResponse{
33-
Message: &flasher.DownloadResponse_Progress{Progress: p},
34-
})
35-
}
36-
37-
client := updater.NewClient()
38-
manifest, err := client.GetInfoManifest(ctx)
39-
if err != nil {
40-
return err
41-
}
42-
43-
var rel *updater.Release
44-
if req.Version == "latest" || req.Version == manifest.Latest.Version {
45-
rel = &manifest.Latest
46-
} else {
47-
for _, r := range manifest.Releases {
48-
if req.Version == r.Version {
49-
rel = &r
50-
break
51-
}
52-
}
53-
}
54-
55-
if rel == nil {
56-
return fmt.Errorf("could not find Debian image %s", req.Version)
57-
}
58-
59-
tmpZip := paths.New(req.GetDownloadPath(), "arduino-unoq-debian-image-"+rel.Version+".tar.zst")
60-
61-
if err := updater.DownloadFile(ctx, tmpZip, rel.Url, rel.Version, downloadCB, downloader.Config{}); err != nil {
62-
return err
63-
}
64-
65-
return syncSend.Send(&flasher.DownloadResponse{
66-
Message: &flasher.DownloadResponse_Result_{
67-
Result: &flasher.DownloadResponse_Result{},
68-
},
69-
})
70-
}
1+
// This file is part of arduino-flasher-cli.
2+
//
3+
// Copyright 2025 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-flasher-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package service
17+
18+
import (
19+
"fmt"
20+
21+
"github.com/arduino/go-paths-helper"
22+
"go.bug.st/downloader/v2"
23+
24+
"github.com/arduino/arduino-flasher-cli/internal/updater"
25+
flasher "github.com/arduino/arduino-flasher-cli/rpc/cc/arduino/flasher/v1"
26+
)
27+
28+
func (s *flasherServerImpl) Download(req *flasher.DownloadRequest, stream flasher.Flasher_DownloadServer) error {
29+
syncSend := NewSynchronizedSend(stream.Send)
30+
ctx := stream.Context()
31+
downloadCB := func(p *flasher.DownloadProgress) {
32+
syncSend.Send(&flasher.DownloadResponse{
33+
Message: &flasher.DownloadResponse_Progress{Progress: p},
34+
})
35+
}
36+
37+
client := updater.NewClient()
38+
manifest, err := client.GetInfoManifest(ctx)
39+
if err != nil {
40+
return err
41+
}
42+
43+
var rel *updater.Release
44+
if req.Version == "latest" || req.Version == manifest.Latest.Version {
45+
rel = &manifest.Latest
46+
} else {
47+
for _, r := range manifest.Releases {
48+
if req.Version == r.Version {
49+
rel = &r
50+
break
51+
}
52+
}
53+
}
54+
55+
if rel == nil {
56+
return fmt.Errorf("could not find Debian image %s", req.Version)
57+
}
58+
59+
tmpZip := paths.New(req.GetDownloadPath(), "arduino-unoq-debian-image-"+rel.Version+".tar.zst")
60+
61+
if err := updater.DownloadFile(ctx, tmpZip, rel.Url, rel.Version, downloadCB, downloader.Config{}); err != nil {
62+
return err
63+
}
64+
65+
return syncSend.Send(&flasher.DownloadResponse{
66+
Message: &flasher.DownloadResponse_Result_{
67+
Result: &flasher.DownloadResponse_Result{},
68+
},
69+
})
70+
}

0 commit comments

Comments
 (0)