itd/api/api.go
Arsen Musayelyan 87fdb7a30a
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Add connection multiplexing, fixing itgui
2023-01-03 00:54:00 -08:00

52 lines
806 B
Go

package api
import (
"io"
"net"
"go.arsenm.dev/itd/internal/rpc"
"storj.io/drpc"
"storj.io/drpc/drpcconn"
)
const DefaultAddr = "/tmp/itd/socket"
type Client struct {
conn drpc.Conn
client rpc.DRPCITDClient
}
func New(sockPath string) (*Client, error) {
conn, err := net.Dial("unix", sockPath)
if err != nil {
return nil, err
}
mconn, err := newMuxConn(conn)
if err != nil {
return nil, err
}
return &Client{
conn: mconn,
client: rpc.NewDRPCITDClient(mconn),
}, 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()
}