Switch to lrpc and use context to handle signals

This commit is contained in:
2022-05-01 11:36:28 -07:00
parent 240e7a5ee4
commit 56dbf0540e
14 changed files with 265 additions and 702 deletions

View File

@@ -1,13 +1,8 @@
package api
import (
"context"
"time"
)
func (c *Client) Remove(paths ...string) error {
return c.fsClient.Call(
context.Background(),
return c.client.Call(
"FS",
"Remove",
paths,
nil,
@@ -15,17 +10,17 @@ func (c *Client) Remove(paths ...string) error {
}
func (c *Client) Rename(old, new string) error {
return c.fsClient.Call(
context.Background(),
"Remove",
return c.client.Call(
"FS",
"Rename",
[2]string{old, new},
nil,
)
}
func (c *Client) Mkdir(paths ...string) error {
return c.fsClient.Call(
context.Background(),
return c.client.Call(
"FS",
"Mkdir",
paths,
nil,
@@ -33,8 +28,8 @@ func (c *Client) Mkdir(paths ...string) error {
}
func (c *Client) ReadDir(dir string) (out []FileInfo, err error) {
err = c.fsClient.Call(
context.Background(),
err = c.client.Call(
"FS",
"ReadDir",
dir,
&out,
@@ -43,59 +38,31 @@ func (c *Client) ReadDir(dir string) (out []FileInfo, err error) {
}
func (c *Client) Upload(dst, src string) (chan FSTransferProgress, error) {
var id string
err := c.fsClient.Call(
context.Background(),
progressCh := make(chan FSTransferProgress, 5)
err := c.client.Call(
"FS",
"Upload",
[2]string{dst, src},
&id,
progressCh,
)
if err != nil {
return nil, err
}
progressCh := make(chan FSTransferProgress, 5)
go func() {
srvValCh, ok := c.srvVals[id]
for !ok {
time.Sleep(100 * time.Millisecond)
srvValCh, ok = c.srvVals[id]
}
for val := range srvValCh {
progressCh <- val.(FSTransferProgress)
}
close(progressCh)
}()
return progressCh, nil
}
func (c *Client) Download(dst, src string) (chan FSTransferProgress, error) {
var id string
err := c.fsClient.Call(
context.Background(),
progressCh := make(chan FSTransferProgress, 5)
err := c.client.Call(
"FS",
"Download",
[2]string{dst, src},
&id,
progressCh,
)
if err != nil {
return nil, err
}
progressCh := make(chan FSTransferProgress, 5)
go func() {
srvValCh, ok := c.srvVals[id]
for !ok {
time.Sleep(100 * time.Millisecond)
srvValCh, ok = c.srvVals[id]
}
for val := range srvValCh {
progressCh <- val.(FSTransferProgress)
}
close(progressCh)
}()
return progressCh, nil
}