itd/api/api.go

38 lines
568 B
Go
Raw Normal View History

2022-04-23 00:12:30 +00:00
package api
import (
"io"
"net"
2022-04-23 00:12:30 +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 {
client *client.Client
2022-04-23 00:12:30 +00:00
}
func New(sockPath string) (*Client, error) {
conn, err := net.Dial("unix", sockPath)
2022-04-23 00:12:30 +00:00
if err != nil {
return nil, err
}
out := &Client{
2022-05-01 18:41:16 +00:00
client: client.New(conn, codec.Default),
2022-04-23 00:12:30 +00:00
}
return out, nil
2022-04-23 00:12:30 +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 {
return c.client.Close()
2022-04-23 00:12:30 +00:00
}