Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust auto check client version to option #84

Merged
merged 1 commit into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions ccore/nebula/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ type (
)

var (
VersionAuto = Version("auto")
Version2_5 = types.Version2_5
Version2_6 = types.Version2_6
Version3_0 = types.Version3_0
versionAuto = Version("auto")

Versions = []Version{
Version2_5 = types.Version2_5
Version2_6 = types.Version2_6
Version3_0 = types.Version3_0

supportedVersions = []Version{
Version3_0,
Version2_6,
Version2_5,
Expand Down
4 changes: 2 additions & 2 deletions ccore/nebula/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (c *defaultClient) Version() Version {
}

func (c *defaultClient) initDriver(checkFn func(types.Driver) error) error {
if c.o.version != VersionAuto {
if c.o.version != versionAuto {
driver, err := types.GetDriver(c.o.version)
if err != nil {
return err
Expand All @@ -93,7 +93,7 @@ func (c *defaultClient) initDriver(checkFn func(types.Driver) error) error {
return nil
}

for _, v := range Versions {
for _, v := range c.o.autoVersions {
driver, err := types.GetDriver(v)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions ccore/nebula/gateway/dao/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ func getMapInfo(valWarp *wrapper.ValueWrapper, _verticesParsedList *list, _edges
}

// Connect return if the nebula connect succeed
func Connect(address string, port int, username string, password string, version nebula.Version) (nsid string, err error) {
nsid, err = pool.NewClient(address, port, username, password, version)
func Connect(address string, port int, username string, password string, opts ...nebula.Option) (nsid string, err error) {
nsid, err = pool.NewClient(address, port, username, password, opts...)
if err != nil {
return "", err
}
Expand Down
3 changes: 1 addition & 2 deletions ccore/nebula/gateway/examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"log"

"github.com/vesoft-inc/nebula-http-gateway/ccore/nebula"
"github.com/vesoft-inc/nebula-http-gateway/ccore/nebula/gateway/dao"
)

Expand All @@ -15,7 +14,7 @@ func main() {
password = "123"
)

nsid, err := dao.Connect(address, port, username, password, nebula.VersionAuto)
nsid, err := dao.Connect(address, port, username, password)
if err != nil {
log.Println("error: ", err)
}
Expand Down
4 changes: 2 additions & 2 deletions ccore/nebula/gateway/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ func ListParams(args string, tmpParameter types.ParameterMap, sessionMap types.P
return nil
}

func NewClient(address string, port int, username string, password string, version nebula.Version) (ncid string, err error) {
func NewClient(address string, port int, username string, password string, opts ...nebula.Option) (ncid string, err error) {
clientMux.Lock()
defer clientMux.Unlock()

host := strings.Join([]string{address, strconv.Itoa(port)}, ":")
c, err := nebula.NewGraphClient([]string{host}, username, password, nebula.WithVersion(version))
c, err := nebula.NewGraphClient([]string{host}, username, password, opts...)
if err != nil {
return "", err
}
Expand Down
13 changes: 12 additions & 1 deletion ccore/nebula/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
type (
Options struct {
version Version
autoVersions []Version
log Logger
graph socketOptions
meta socketOptions
Expand All @@ -37,6 +38,15 @@ func WithVersion(version Version) Option {
}
}

func WithAutoVersions(autoVersions ...Version) Option {
return func(o *Options) {
o.version = versionAuto
if len(autoVersions) > 0 {
o.autoVersions = autoVersions
}
}
}

func WithLogger(log Logger) Option {
return func(o *Options) {
o.log = log
Expand Down Expand Up @@ -177,7 +187,8 @@ func (o *socketOptions) complete() {

func defaultOptions() Options {
return Options{
version: VersionAuto,
version: versionAuto,
autoVersions: supportedVersions,
log: noOpLogger{},
graph: defaultSocketOptions(),
meta: defaultSocketOptions(),
Expand Down