From 814a5ea711b13ac972e74663f701362867065ccf Mon Sep 17 00:00:00 2001 From: Katz <47083415+1uvu@users.noreply.github.com> Date: Mon, 17 Jan 2022 17:35:26 +0800 Subject: [PATCH] add client version message in connect response for gateway --- ccore/nebula/examples/main.go | 19 +++++++++++++------ ccore/nebula/gateway/dao/dao.go | 6 +++--- ccore/nebula/gateway/examples/main.go | 6 +++--- ccore/nebula/gateway/pool/pool.go | 11 ++++++----- controllers/db.go | 4 ++-- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/ccore/nebula/examples/main.go b/ccore/nebula/examples/main.go index 1450dfc..1bd8f7a 100644 --- a/ccore/nebula/examples/main.go +++ b/ccore/nebula/examples/main.go @@ -10,18 +10,25 @@ import ( "github.com/vesoft-inc/nebula-http-gateway/ccore/nebula/wrapper" ) +type TestCase struct { + version nebula.Version + host string +} + func main() { - for _, version := range []nebula.Version{ - nebula.Version2_5, - nebula.Version2_6, - nebula.Version3_0, - } { + testCases := []TestCase{ + {nebula.Version2_5, "192.168.8.157:9669"}, + {nebula.Version2_6, "192.168.8.157:9669"}, + {nebula.Version3_0, "192.168.8.143:9669"}, + } + for _, testCase := range testCases { var ( c nebula.Client gc nebula.GraphClient err error - host = "192.168.8.167:9669" + version = testCase.version + host = testCase.host username = "root" password = "123" ) diff --git a/ccore/nebula/gateway/dao/dao.go b/ccore/nebula/gateway/dao/dao.go index b461dfb..ecb000f 100644 --- a/ccore/nebula/gateway/dao/dao.go +++ b/ccore/nebula/gateway/dao/dao.go @@ -276,10 +276,10 @@ 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, opts ...nebula.Option) (nsid string, err error) { - nsid, err = pool.NewClient(address, port, username, password, opts...) +func Connect(address string, port int, username string, password string, opts ...nebula.Option) (nsid string, ver nebula.Version, err error) { + nsid, ver, err = pool.NewClient(address, port, username, password, opts...) if err != nil { - return "", err + return "", "", err } return } diff --git a/ccore/nebula/gateway/examples/main.go b/ccore/nebula/gateway/examples/main.go index 7c5c8ed..4ec8b49 100644 --- a/ccore/nebula/gateway/examples/main.go +++ b/ccore/nebula/gateway/examples/main.go @@ -8,17 +8,17 @@ import ( func main() { var ( - address = "192.168.8.167" + address = "192.168.8.143" port = 9669 username = "root" password = "123" ) - nsid, err := dao.Connect(address, port, username, password) + nsid, ver, err := dao.Connect(address, port, username, password) if err != nil { log.Println("error: ", err) } - log.Println(nsid) + log.Println(nsid, ver) defer dao.Disconnect(nsid) gql := "CREATE SPACE IF NOT EXISTS basic_example_space(vid_type=FIXED_STRING(20)); " + diff --git a/ccore/nebula/gateway/pool/pool.go b/ccore/nebula/gateway/pool/pool.go index 6443944..f2d8a97 100644 --- a/ccore/nebula/gateway/pool/pool.go +++ b/ccore/nebula/gateway/pool/pool.go @@ -202,25 +202,26 @@ func ListParams(args string, tmpParameter types.ParameterMap, sessionMap types.P return nil } -func NewClient(address string, port int, username string, password string, opts ...nebula.Option) (ncid string, err error) { +func NewClient(address string, port int, username string, password string, opts ...nebula.Option) (ncid string, ver nebula.Version, err error) { clientMux.Lock() defer clientMux.Unlock() host := strings.Join([]string{address, strconv.Itoa(port)}, ":") c, err := nebula.NewGraphClient([]string{host}, username, password, opts...) if err != nil { - return "", err + return "", "", err } if err := c.Open(); err != nil { - return "", err + return "", "", err } u, err := uuid.NewV4() if err != nil { - return "", err + return "", "", err } ncid = u.String() + ver = c.Version() client := &Client{ graphClient: c, @@ -239,7 +240,7 @@ func NewClient(address string, port int, username string, password string, opts // Make a goroutine to deal with concurrent requests from each connection go handleRequest(ncid) - return ncid, err + return ncid, ver, err } func handleRequest(ncid string) { diff --git a/controllers/db.go b/controllers/db.go index 2413fb2..018b0e7 100644 --- a/controllers/db.go +++ b/controllers/db.go @@ -48,7 +48,7 @@ func (this *DatabaseController) Connect() { ) json.Unmarshal(this.Ctx.Input.RequestBody, ¶ms) - nsid, err := dao.Connect(params.Address, params.Port, params.Username, params.Password) + nsid, ver, err := dao.Connect(params.Address, params.Port, params.Username, params.Password) if err == nil { res.Code = 0 m := make(map[string]types.Any) @@ -58,7 +58,7 @@ func (this *DatabaseController) Connect() { this.Ctx.SetCookie("SameSite", "Strict") this.SetSession(beego.AppConfig.String("sessionkey"), nsid) - res.Message = "Login successfully" + res.Message = string(ver) } else { res.Code = -1 res.Message = err.Error()