Add doc comments
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Elara 2023-01-03 09:30:04 -08:00
parent de3ce406e7
commit 547c79f874
2 changed files with 10 additions and 0 deletions

View File

@ -10,11 +10,15 @@ import (
const DefaultAddr = "/tmp/itd/socket" const DefaultAddr = "/tmp/itd/socket"
// Client is a client for ITD's socket API
type Client struct { type Client struct {
conn drpc.Conn conn drpc.Conn
client rpc.DRPCITDClient client rpc.DRPCITDClient
} }
// New connects to the UNIX socket at the given
// path, and returns a client that communicates
// with that socket.
func New(sockPath string) (*Client, error) { func New(sockPath string) (*Client, error) {
conn, err := net.Dial("unix", sockPath) conn, err := net.Dial("unix", sockPath)
if err != nil { if err != nil {
@ -32,6 +36,8 @@ func New(sockPath string) (*Client, error) {
}, nil }, nil
} }
// NewFromConn returns a client that communicates
// over the given connection.
func NewFromConn(conn io.ReadWriteCloser) (*Client, error) { func NewFromConn(conn io.ReadWriteCloser) (*Client, error) {
mconn, err := newMuxConn(conn) mconn, err := newMuxConn(conn)
if err != nil { if err != nil {
@ -44,10 +50,12 @@ func NewFromConn(conn io.ReadWriteCloser) (*Client, error) {
}, nil }, nil
} }
// FS returns the filesystem API client
func (c *Client) FS() *FSClient { func (c *Client) FS() *FSClient {
return &FSClient{rpc.NewDRPCFSClient(c.conn)} return &FSClient{rpc.NewDRPCFSClient(c.conn)}
} }
// Close closes the client connection
func (c *Client) Close() error { func (c *Client) Close() error {
return c.conn.Close() return c.conn.Close()
} }

View File

@ -11,6 +11,8 @@ import (
var _ drpc.Conn = &muxConn{} var _ drpc.Conn = &muxConn{}
// muxConn implements drpc.Conn using the yamux
// multiplexer to allow concurrent RPCs
type muxConn struct { type muxConn struct {
conn io.ReadWriteCloser conn io.ReadWriteCloser
sess *yamux.Session sess *yamux.Session