Add the file command with read subcommand

This commit is contained in:
2022-05-13 22:45:15 +02:00
parent 5bd76e6048
commit 7197fce351
7 changed files with 374 additions and 63 deletions

27
pkg/portal/file.go Normal file
View File

@@ -0,0 +1,27 @@
package portal
import (
"context"
"os"
"github.com/apex/log"
"github.com/dpogorzelski/speedrun/proto/portal"
)
func (s *Server) FileRead(ctx context.Context, file *portal.FileReadRequest) (*portal.FileReadResponse, error) {
fields := log.Fields{
"context": "file",
"command": "read",
"name": file.GetPath(),
}
log := log.WithFields(fields)
log.Debug("Received file read request")
content, err := os.ReadFile(file.GetPath())
if err != nil {
log.Error(err.Error())
return nil, err
}
return &portal.FileReadResponse{State: portal.State_UNKNOWN, Content: string(content)}, nil
}