Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
allow setting custom dial options; addresses #124
Browse files Browse the repository at this point in the history
Signed-off-by: Denys Smirnov <denis.smirnov.91@gmail.com>
  • Loading branch information
dennwc committed Jun 26, 2019
1 parent 33c5787 commit 66bce32
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ type Client struct {
}

// NewClientContext returns a new bblfsh client given a bblfshd endpoint.
func NewClientContext(ctx context.Context, endpoint string) (*Client, error) {
func NewClientContext(ctx context.Context, endpoint string, options ...grpc.DialOption) (*Client, error) {
opts := []grpc.DialOption{
grpc.WithBlock(),
grpc.WithInsecure(),
}
opts = append(opts, protocol2.DialOptions()...)
// user-defined options should go last
// this allows to override any default option
opts = append(opts, options...)

conn, err := grpc.DialContext(ctx, endpoint, opts...)
if err != nil {
Expand All @@ -39,11 +42,11 @@ func NewClientContext(ctx context.Context, endpoint string) (*Client, error) {
// NewClient is the same as NewClientContext, but assumes a default timeout for the connection.
//
// Deprecated: use NewClientContext instead
func NewClient(endpoint string) (*Client, error) {
func NewClient(endpoint string, options ...grpc.DialOption) (*Client, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

return NewClientContext(ctx, endpoint)
return NewClientContext(ctx, endpoint, options...)
}

// NewClientWithConnection returns a new bblfsh client given a grpc connection.
Expand Down

0 comments on commit 66bce32

Please sign in to comment.