2022-04-23 00:12:30 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2022-05-08 04:23:42 +00:00
|
|
|
"io"
|
2022-05-01 18:36:28 +00:00
|
|
|
"net"
|
2022-04-23 00:12:30 +00:00
|
|
|
|
2022-05-01 18:36:28 +00:00
|
|
|
"go.arsenm.dev/lrpc/client"
|
|
|
|
"go.arsenm.dev/lrpc/codec"
|
2022-04-23 00:12:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const DefaultAddr = "/tmp/itd/socket"
|
|
|
|
|
|
|
|
type Client struct {
|
2022-05-01 18:36:28 +00:00
|
|
|
client *client.Client
|
2022-04-23 00:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func New(sockPath string) (*Client, error) {
|
2022-05-01 18:36:28 +00:00
|
|
|
conn, err := net.Dial("unix", sockPath)
|
2022-04-23 00:12:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-05-01 18:36:28 +00:00
|
|
|
out := &Client{
|
2022-05-01 18:41:16 +00:00
|
|
|
client: client.New(conn, codec.Default),
|
2022-04-23 00:12:30 +00:00
|
|
|
}
|
2022-05-01 18:36:28 +00:00
|
|
|
return out, nil
|
2022-04-23 00:12:30 +00:00
|
|
|
}
|
|
|
|
|
2022-05-08 04:23:42 +00:00
|
|
|
func NewFromConn(conn io.ReadWriteCloser) *Client {
|
|
|
|
return &Client{
|
|
|
|
client: client.New(conn, codec.Default),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 00:12:30 +00:00
|
|
|
func (c *Client) Close() error {
|
2022-05-01 18:36:28 +00:00
|
|
|
return c.client.Close()
|
2022-04-23 00:12:30 +00:00
|
|
|
}
|