From 0ca3dae3763f8e37a0f2e281eed342b31c201317 Mon Sep 17 00:00:00 2001 From: Aiee <18348405+Aiee@users.noreply.github.com> Date: Tue, 2 Nov 2021 17:38:19 +0800 Subject: [PATCH 1/2] Fix parsing JSON example and add it into action --- Makefile | 1 + json_example/parse_json_example.go | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 76d39677..d79a7a4d 100644 --- a/Makefile +++ b/Makefile @@ -40,4 +40,5 @@ run-examples: cd .. && \ go run basic_example/graph_client_basic_example.go && \ go run gorountines_example/graph_client_goroutines_example.go && \ + go run json_example/parse_json_example.go && \ cd ./nebula-docker-compose && docker-compose down -v diff --git a/json_example/parse_json_example.go b/json_example/parse_json_example.go index 50667802..c6d572a4 100644 --- a/json_example/parse_json_example.go +++ b/json_example/parse_json_example.go @@ -65,8 +65,8 @@ type JsonObj struct { Comment string `json:"comment "` } `json:"results"` Errors []struct { - ErrorCode int `json:"errorCode"` - ErrorMsg string `json:"errorMsg"` + Code int `json:"code"` + Message string `json:"message"` } `json:"errors"` } @@ -118,7 +118,25 @@ func main() { // Get a property birthday := jsonObj.Results[0].Data[0].Row[0].(map[string]interface{})["person.birthday"] - fmt.Printf("person.birthday is %s \n", birthday) + fmt.Printf("person.birthday is %s \n\n", birthday) + } + // With error + { + jsonStrResult, err := session.ExecuteJson("MAT (v:person {name: \"Bob\"}) RETURN v") + if err != nil { + log.Fatal(fmt.Sprintf("fail to get the result in json format, %s", err.Error())) + } + + var jsonObj JsonObj + // Parse JSON + json.Unmarshal(jsonStrResult, &jsonObj) + // Get error message + errorMsg := jsonObj.Errors[0].Message + msg, err := json.MarshalIndent(errorMsg, "", " ") + if err != nil { + fmt.Println("error:", err) + } + fmt.Println("Error message: ", string(msg)) } dropSpace(session, "client_test") From 25f02fb72877678f070a563b90ca0e37f571e1d5 Mon Sep 17 00:00:00 2001 From: Aiee <18348405+Aiee@users.noreply.github.com> Date: Tue, 2 Nov 2021 17:42:17 +0800 Subject: [PATCH 2/2] Fix port in the example --- json_example/parse_json_example.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_example/parse_json_example.go b/json_example/parse_json_example.go index c6d572a4..74738900 100644 --- a/json_example/parse_json_example.go +++ b/json_example/parse_json_example.go @@ -18,7 +18,7 @@ const ( address = "127.0.0.1" // The default port of Nebula Graph 2.x is 9669. // 3699 is only for testing. - port = 29562 + port = 3699 username = "root" password = "nebula" )