-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
105 changed files
with
370,430 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/vesoft-inc/nebula-http-gateway/ccore | ||
|
||
go 1.16 | ||
|
||
require github.com/facebook/fbthrift v0.31.1-0.20210223140454-614a73a42488 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/facebook/fbthrift v0.31.1-0.20210223140454-614a73a42488 h1:A4KCT0mvTBkvb93gGN+efLPkrgTqmqMeaLDG51KVhMM= | ||
github.com/facebook/fbthrift v0.31.1-0.20210223140454-614a73a42488/go.mod h1:2tncLx5rmw69e5kMBv/yJneERbzrr1yr5fdlnTbu8lU= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package nebula | ||
|
||
import ( | ||
"github.com/vesoft-inc/nebula-http-gateway/ccore/nebula/types" | ||
) | ||
|
||
type ( | ||
Version = types.Version | ||
AuthResponse = types.AuthResponse | ||
ExecutionResponse = types.ExecutionResponse | ||
) | ||
|
||
var ( | ||
V2_0_0 = types.V2_0_0 | ||
V2_5_0 = types.V2_5_0 | ||
V2_5_1 = types.V2_5_1 | ||
V2_6_0 = types.V2_6_0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package nebula | ||
|
||
import "github.com/vesoft-inc/nebula-http-gateway/ccore/nebula/types" | ||
|
||
type ( | ||
Client interface { | ||
Graph() GraphClient | ||
Meta() MetaClient | ||
StorageAdmin() StorageAdminClient | ||
} | ||
|
||
ConnectionInfo struct { | ||
GraphEndpoints []string | ||
MetaEndpoints []string | ||
StorageAdminEndpoints []string | ||
GraphAccount Account | ||
} | ||
|
||
Account struct { | ||
Username string | ||
Password string | ||
} | ||
|
||
defaultClient struct { | ||
o Options | ||
driver types.Driver | ||
graph *driverGraph | ||
meta *driverMeta | ||
storageAdmin *driverStorageAdmin | ||
} | ||
) | ||
|
||
func NewClient(info ConnectionInfo, opts ...Option) (Client, error) { | ||
o := defaultOptions() | ||
for _, opt := range opts { | ||
opt(&o) | ||
} | ||
o.complete() | ||
if err := o.validate(); err != nil { | ||
return nil, err | ||
} | ||
|
||
driver, err := types.GetDriver(o.version) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &defaultClient{ | ||
o: o, | ||
driver: driver, | ||
graph: newDriverGraph(info.GraphEndpoints, info.GraphAccount.Username, info.GraphAccount.Password, &o.graph), | ||
meta: newDriverMeta(info.MetaEndpoints, &o.meta), | ||
storageAdmin: newDriverStorageAdmin(info.StorageAdminEndpoints, &o.storageAdmin), | ||
}, nil | ||
} | ||
|
||
func (c *defaultClient) Graph() GraphClient { | ||
return (*defaultGraphClient)(c) | ||
} | ||
|
||
func (c *defaultClient) Meta() MetaClient { | ||
return (*defaultMetaClient)(c) | ||
} | ||
|
||
func (c *defaultClient) StorageAdmin() StorageAdminClient { | ||
return (*defaultStorageAdminClient)(c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package nebula | ||
|
||
import "github.com/vesoft-inc/nebula-http-gateway/ccore/nebula/types" | ||
|
||
type ( | ||
GraphClient interface { | ||
Open() error | ||
Execute(stmt []byte) (ExecutionResponse, error) | ||
ExecuteJson(stmt []byte) ([]byte, error) | ||
Close() error | ||
} | ||
|
||
defaultGraphClient defaultClient | ||
) | ||
|
||
func NewGraphClient(endpoints []string, username, password string, opts ...Option) (GraphClient, error) { | ||
o := defaultOptions() | ||
for _, opt := range opts { | ||
opt(&o) | ||
} | ||
o.complete() | ||
if err := o.validate(); err != nil { | ||
return nil, err | ||
} | ||
|
||
driver, err := types.GetDriver(o.version) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &defaultGraphClient{ | ||
o: o, | ||
driver: driver, | ||
graph: newDriverGraph(endpoints, username, password, &o.graph), | ||
}, nil | ||
} | ||
|
||
func (c *defaultGraphClient) Open() error { | ||
return c.graph.open(c.driver) | ||
} | ||
|
||
func (c *defaultGraphClient) Execute(stmt []byte) (ExecutionResponse, error) { | ||
return c.graph.Execute(c.graph.sessionId, stmt) | ||
} | ||
|
||
func (c *defaultGraphClient) ExecuteJson(stmt []byte) ([]byte, error) { | ||
if err := c.graph.open(c.driver); err != nil { | ||
return nil, err | ||
} | ||
|
||
return c.graph.ExecuteJson(c.graph.sessionId, stmt) | ||
} | ||
|
||
func (c *defaultGraphClient) Close() error { | ||
return c.graph.open(c.driver) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package nebula | ||
|
||
import "github.com/vesoft-inc/nebula-http-gateway/ccore/nebula/types" | ||
|
||
type ( | ||
MetaClient interface { | ||
Open() error | ||
Close() error | ||
} | ||
|
||
defaultMetaClient defaultClient | ||
) | ||
|
||
func NewMetaClient(endpoints []string, opts ...Option) (MetaClient, error) { | ||
o := defaultOptions() | ||
for _, opt := range opts { | ||
opt(&o) | ||
} | ||
o.complete() | ||
if err := o.validate(); err != nil { | ||
return nil, err | ||
} | ||
|
||
driver, err := types.GetDriver(o.version) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &defaultMetaClient{ | ||
o: o, | ||
driver: driver, | ||
meta: newDriverMeta(endpoints, &o.meta), | ||
}, nil | ||
} | ||
|
||
func (c *defaultMetaClient) Open() error { | ||
return c.meta.open(c.driver) | ||
} | ||
|
||
func (c *defaultMetaClient) Close() error { | ||
return c.meta.open(c.driver) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package nebula | ||
|
||
import "github.com/vesoft-inc/nebula-http-gateway/ccore/nebula/types" | ||
|
||
type ( | ||
StorageAdminClient interface { | ||
Open() error | ||
Close() error | ||
} | ||
|
||
defaultStorageAdminClient defaultClient | ||
) | ||
|
||
func NewStorageAdminClient(endpoints []string, opts ...Option) (StorageAdminClient, error) { | ||
o := defaultOptions() | ||
for _, opt := range opts { | ||
opt(&o) | ||
} | ||
o.complete() | ||
if err := o.validate(); err != nil { | ||
return nil, err | ||
} | ||
|
||
driver, err := types.GetDriver(o.version) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &defaultStorageAdminClient{ | ||
o: o, | ||
driver: driver, | ||
storageAdmin: newDriverStorageAdmin(endpoints, &o.storageAdmin), | ||
}, nil | ||
} | ||
|
||
func (c *defaultStorageAdminClient) Open() error { | ||
return c.storageAdmin.open(c.driver) | ||
} | ||
|
||
func (c *defaultStorageAdminClient) Close() error { | ||
return c.storageAdmin.open(c.driver) | ||
} |
Oops, something went wrong.