Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 97a231f

Browse files
committed
#1447 - back-end usage scenario
Add `FilesService` impl.
1 parent b9bebad commit 97a231f

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

‎cli/daemon/daemon.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/arduino/arduino-cli/metrics"
3434
srv_commands "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3535
srv_debug "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/debug/v1"
36+
srv_files "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/files/v1"
3637
srv_monitor "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/monitor/v1"
3738
srv_settings "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/settings/v1"
3839
"github.com/segmentio/stats/v4"
@@ -98,6 +99,9 @@ func runDaemonCommand(cmd *cobra.Command, args []string) {
9899
// Register the debug session service
99100
srv_debug.RegisterDebugServiceServer(s, &daemon.DebugService{})
100101

102+
// Register the files service
103+
srv_files.RegisterFilesServiceServer(s, &daemon.FilesService{})
104+
101105
if !daemonize {
102106
// When parent process ends terminate also the daemon
103107
go func() {

‎commands/daemon/files.go‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 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-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 license@arduino.cc.
15+
16+
package daemon
17+
18+
import (
19+
"context"
20+
"os"
21+
22+
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/files/v1"
23+
)
24+
25+
// FilesService implements the `Files` service
26+
type FilesService struct {
27+
rpc.UnimplementedFilesServiceServer
28+
}
29+
30+
// LoadFile returns a requested file content or an error.
31+
func (s *FilesService) LoadFile(ctx context.Context, req *rpc.LoadFileRequest) (*rpc.LoadFileResponse, error) {
32+
content, err := os.ReadFile(req.Path)
33+
if err == nil {
34+
return &rpc.LoadFileResponse{
35+
Content: content,
36+
Type: rpc.ContentType_CONTENT_TYPE_RAW_UNSPECIFIED,
37+
}, nil
38+
}
39+
40+
return nil, err
41+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /