NewClient creates a new socket client and opens a connection to the socket. If path is not provided via WithPath or is empty, it will auto-discover the default socket path.
(ctx context.Context, opts ...Option)
| 40 | // If path is not provided via WithPath or is empty, it will auto-discover the |
| 41 | // default socket path. |
| 42 | func NewClient(ctx context.Context, opts ...Option) (*Client, error) { |
| 43 | options := &options{} |
| 44 | for _, opt := range opts { |
| 45 | opt(options) |
| 46 | } |
| 47 | |
| 48 | conn, err := dialSocket(ctx, options.path) |
| 49 | if err != nil { |
| 50 | return nil, xerrors.Errorf("connect to socket: %w", err) |
| 51 | } |
| 52 | |
| 53 | drpcConn := drpcconn.New(conn) |
| 54 | client := proto.NewDRPCAgentSocketClient(drpcConn) |
| 55 | |
| 56 | return &Client{ |
| 57 | client: client, |
| 58 | conn: drpcConn, |
| 59 | }, nil |
| 60 | } |
| 61 | |
| 62 | // Close closes the socket connection. |
| 63 | func (c *Client) Close() error { |