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

Commit

Permalink
update the client to support v2 protocol
Browse files Browse the repository at this point in the history
Signed-off-by: Denys Smirnov <denys@sourced.tech>
  • Loading branch information
Denys Smirnov authored and dennwc committed Aug 3, 2018
1 parent 1fa42cc commit c7e83b8
Show file tree
Hide file tree
Showing 7 changed files with 434 additions and 80 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: go
go_import_path: gopkg.in/bblfsh/client-go.v2

env:
- BBLFSHD_VERSION=v2.6.1 BBLFSH_PYTHON_VERSION=v2.2.1
install:
- |
if [[ $TRAVIS_OS_NAME = linux ]]; then
Expand All @@ -9,8 +11,8 @@ install:
sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install gcc-6 g++-6
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 90
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 90
docker run --privileged -d -p 9432:9432 --name bblfsh bblfsh/bblfshd
docker exec -it bblfsh bblfshctl driver install python bblfsh/python-driver
docker run --privileged -d -p 9432:9432 --name bblfshd bblfsh/bblfshd:$BBLFSHD_VERSION
docker exec bblfshd bblfshctl driver install bblfsh/python-driver:$BBLFSH_PYTHON_VERSION
fi
- make dependencies

Expand Down
190 changes: 190 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.

[[constraint]]
name = "github.com/jessevdk/go-flags"
version = "1.4.x"

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.2.x"

[[constraint]]
name = "google.golang.org/grpc"
version = "1.14.x"

[[constraint]]
name = "gopkg.in/bblfsh/sdk.v1"
version = "1.16.x"

[[constraint]]
branch = "v2"
name = "gopkg.in/bblfsh/sdk.v2"

[prune]
go-tests = true
unused-packages = true
35 changes: 24 additions & 11 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,57 @@
package bblfsh

import (
"context"
"time"

"google.golang.org/grpc"
"gopkg.in/bblfsh/sdk.v1/protocol"
protocol1 "gopkg.in/bblfsh/sdk.v1/protocol"
protocol2 "gopkg.in/bblfsh/sdk.v2/protocol"
)

// Client holds the public client API to interact with the bblfsh daemon.
type Client struct {
*grpc.ClientConn
service protocol.ProtocolServiceClient
service1 protocol1.ProtocolServiceClient
service2 protocol2.DriverClient
}

// NewClient returns a new bblfsh client given a bblfshd endpoint.
func NewClient(endpoint string) (*Client, error) {
// NewClientContext returns a new bblfsh client given a bblfshd endpoint.
func NewClientContext(ctx context.Context, endpoint string) (*Client, error) {
opts := []grpc.DialOption{
grpc.WithTimeout(5 * time.Second),
grpc.WithBlock(),
grpc.WithInsecure(),
}

conn, err := grpc.Dial(endpoint, opts...)
conn, err := grpc.DialContext(ctx, endpoint, opts...)
if err != nil {
return nil, err
}
return &Client{
ClientConn: conn,
service: protocol.NewProtocolServiceClient(conn),
}, nil
return NewClientWithConnection(conn)
}

// NewClient is the same as NewClientContext, but assumes a default timeout for the connection.
func NewClient(endpoint string) (*Client, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

return NewClientContext(ctx, endpoint)
}

// NewClientWithConnection returns a new bblfsh client given a grpc connection.
func NewClientWithConnection(conn *grpc.ClientConn) (*Client, error) {
return &Client{
ClientConn: conn,
service: protocol.NewProtocolServiceClient(conn),
service1: protocol1.NewProtocolServiceClient(conn),
service2: protocol2.NewDriverClient(conn),
}, nil
}

// NewParseRequestV2 is a parsing request to get the UAST.
func (c *Client) NewParseRequestV2() *ParseRequestV2 {
return &ParseRequestV2{client: c}
}

// NewParseRequest is a parsing request to get the UAST.
func (c *Client) NewParseRequest() *ParseRequest {
return &ParseRequest{client: c}
Expand Down
Loading

0 comments on commit c7e83b8

Please sign in to comment.