itd/api/api.go
Arsen Musayelyan b757af7fed
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Switch to autogenerated DRPC framework
2023-01-02 22:30:17 -08:00

47 lines
752 B
Go

package api
import (
"io"
"net"
"go.arsenm.dev/itd/internal/rpc"
"storj.io/drpc/drpcconn"
)
const DefaultAddr = "/tmp/itd/socket"
type Client struct {
conn *drpcconn.Conn
client rpc.DRPCITDClient
}
func New(sockPath string) (*Client, error) {
conn, err := net.Dial("unix", sockPath)
if err != nil {
return nil, err
}
dconn := drpcconn.New(conn)
return &Client{
conn: dconn,
client: rpc.NewDRPCITDClient(dconn),
}, nil
}
func NewFromConn(conn io.ReadWriteCloser) *Client {
dconn := drpcconn.New(conn)
return &Client{
conn: dconn,
client: rpc.NewDRPCITDClient(dconn),
}
}
func (c *Client) FS() *FSClient {
return &FSClient{rpc.NewDRPCFSClient(c.conn)}
}
func (c *Client) Close() error {
return c.conn.Close()
}