You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hugegraph.apache.org by ji...@apache.org on 2023/11/01 07:36:34 UTC
(incubator-hugegraph-toolchain) branch tmp-go updated (fdf36c9d -> 3f71ec0c)
This is an automated email from the ASF dual-hosted git repository.
jin pushed a change to branch tmp-go
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph-toolchain.git
from fdf36c9d add Gremlin post API
new fe05caf2 add property apis
new 3f71ec0c add apis
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
hugegraph-client-go/api/api.resquest.go | 11 +-
hugegraph-client-go/api/v1/api._.go | 25 ++++
hugegraph-client-go/api/v1/api.gremlin.get.go | 120 ++++++++++++++++
...retx.create_test.go => api.gremlin.get_test.go} | 40 +++---
hugegraph-client-go/api/v1/api.gremlin.post.go | 26 +++-
.../api/v1/api.gremlin.post_test.go | 17 +++
.../api/v1/api.propertykey.create.go | 126 +++++++++++++++++
...eate_test.go => api.propertykey.create_test.go} | 45 +++---
.../api/v1/api.propertykey.delete_by_name.go | 105 ++++++++++++++
.../api/v1/api.propertykey.delete_by_name_test.go | 12 +-
.../api/v1/api.propertykey.get_all.go | 101 ++++++++++++++
...ate_test.go => api.propertykey.get_all_test.go} | 25 +---
.../api/v1/api.propertykey.get_by_name.go | 117 ++++++++++++++++
...test.go => api.propertykey.get_by_name_test.go} | 25 +---
.../api/v1/api.propertykey.update_userdata.go | 144 ++++++++++++++++++++
....go => api.propertykey.update_userdata_test.go} | 40 +++---
hugegraph-client-go/api/v1/api.schema.go | 151 +++++++++++++++++++++
...pi.veretx.create_test.go => api.schema_test.go} | 23 +---
hugegraph-client-go/api/v1/api.veretx.create.go | 3 +-
hugegraph-client-go/api/v1/api.version.go | 2 +-
hugegraph-client-go/api/v1/api.version_test.go | 56 +-------
hugegraph-client-go/internal/model/model.go | 10 ++
22 files changed, 1045 insertions(+), 179 deletions(-)
create mode 100644 hugegraph-client-go/api/v1/api.gremlin.get.go
copy hugegraph-client-go/api/v1/{api.veretx.create_test.go => api.gremlin.get_test.go} (65%)
create mode 100644 hugegraph-client-go/api/v1/api.propertykey.create.go
copy hugegraph-client-go/api/v1/{api.veretx.create_test.go => api.propertykey.create_test.go} (53%)
create mode 100644 hugegraph-client-go/api/v1/api.propertykey.delete_by_name.go
copy hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/entity/schema/Timefiable.java => hugegraph-client-go/api/v1/api.propertykey.delete_by_name_test.go (84%)
create mode 100644 hugegraph-client-go/api/v1/api.propertykey.get_all.go
copy hugegraph-client-go/api/v1/{api.veretx.create_test.go => api.propertykey.get_all_test.go} (69%)
create mode 100644 hugegraph-client-go/api/v1/api.propertykey.get_by_name.go
copy hugegraph-client-go/api/v1/{api.veretx.create_test.go => api.propertykey.get_by_name_test.go} (68%)
create mode 100644 hugegraph-client-go/api/v1/api.propertykey.update_userdata.go
copy hugegraph-client-go/api/v1/{api.veretx.create_test.go => api.propertykey.update_userdata_test.go} (58%)
create mode 100644 hugegraph-client-go/api/v1/api.schema.go
copy hugegraph-client-go/api/v1/{api.veretx.create_test.go => api.schema_test.go} (70%)
(incubator-hugegraph-toolchain) 01/02: add property apis
Posted by ji...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jin pushed a commit to branch tmp-go
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph-toolchain.git
commit fe05caf21db5779477c77ef28f18e167010d8fbf
Author: izliang <iz...@qq.com>
AuthorDate: Wed Nov 1 11:34:55 2023 +0800
add property apis
Change-Id: I0ce53e64effc7d2affcac577e9c4d0405129ddf1
---
hugegraph-client-go/api/v1/api._.go | 19 +++
hugegraph-client-go/api/v1/api.gremlin.post.go | 24 +++-
.../api/v1/api.gremlin.post_test.go | 17 +++
.../api/v1/api.propertykey.create.go | 126 +++++++++++++++++
.../api/v1/api.propertykey.create_test.go | 61 +++++++++
.../api/v1/api.propertykey.delete_by_name.go | 105 ++++++++++++++
.../v1/api.propertykey.delete_by_name_test.go} | 13 +-
.../api/v1/api.propertykey.get_all.go | 101 ++++++++++++++
.../v1/api.propertykey.get_all_test.go} | 24 +++-
.../api/v1/api.propertykey.get_by_name.go | 117 ++++++++++++++++
.../v1/api.propertykey.get_by_name_test.go} | 24 +++-
hugegraph-client-go/api/v1/api.schema.go | 151 +++++++++++++++++++++
.../model/model.go => api/v1/api.schema_test.go} | 24 +++-
hugegraph-client-go/api/v1/api.veretx.create.go | 1 +
hugegraph-client-go/api/v1/api.version_test.go | 56 +-------
hugegraph-client-go/internal/model/model.go | 10 ++
16 files changed, 794 insertions(+), 79 deletions(-)
diff --git a/hugegraph-client-go/api/v1/api._.go b/hugegraph-client-go/api/v1/api._.go
index e509377c..759791a4 100644
--- a/hugegraph-client-go/api/v1/api._.go
+++ b/hugegraph-client-go/api/v1/api._.go
@@ -24,18 +24,26 @@ import (
// API contains the Hugegraph APIs
type APIV1 struct {
Version Version
+ Schema Schema
Vertex struct {
Create
}
Gremlin struct {
GremlinPost
}
+ PropertyKey struct {
+ PropertyKeyGetAll
+ PropertyKeyGetByName
+ PropertyKeyCreate
+ PropertyKeyDeleteByName
+ }
}
// New creates new API
func New(t api.Transport) *APIV1 {
return &APIV1{
Version: newVersionFunc(t),
+ Schema: newSchemaFunc(t),
Vertex: struct {
Create
}{
@@ -46,5 +54,16 @@ func New(t api.Transport) *APIV1 {
}{
GremlinPost: newGremlinPostFunc(t),
},
+ PropertyKey: struct {
+ PropertyKeyGetAll
+ PropertyKeyGetByName
+ PropertyKeyCreate
+ PropertyKeyDeleteByName
+ }{
+ PropertyKeyGetAll: newPropertyKeyGetAllFunc(t),
+ PropertyKeyGetByName: newPropertyKeyGetByNameFunc(t),
+ PropertyKeyCreate: newPropertyKeyCreateFunc(t),
+ PropertyKeyDeleteByName: newPropertyKeyDeleteByNameFunc(t),
+ },
}
}
diff --git a/hugegraph-client-go/api/v1/api.gremlin.post.go b/hugegraph-client-go/api/v1/api.gremlin.post.go
index 846ab39f..17ccb6a5 100644
--- a/hugegraph-client-go/api/v1/api.gremlin.post.go
+++ b/hugegraph-client-go/api/v1/api.gremlin.post.go
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
package v1
import (
@@ -83,22 +100,21 @@ func (g GremlinPostRequest) Do(ctx context.Context, transport api.Transport) (*G
if len(g.language) < 1 {
g.language = "gremlin-groovy"
}
-
+
gd := &GremlinPostRequestData{
Gremlin: g.gremlin,
Bindings: g.bindings,
Language: g.language,
Aliases: g.aliases,
}
-
+
byteBody, err := json.Marshal(&gd) // 序列化
if err != nil {
return nil, err
}
- reader := strings.NewReader(string(byteBody)) // 转化为reader
-
+ reader := strings.NewReader(string(byteBody))
req, _ := api.NewRequest("POST", "/gremlin", reader)
if ctx != nil {
diff --git a/hugegraph-client-go/api/v1/api.gremlin.post_test.go b/hugegraph-client-go/api/v1/api.gremlin.post_test.go
index eb4c65d4..d67f521c 100644
--- a/hugegraph-client-go/api/v1/api.gremlin.post_test.go
+++ b/hugegraph-client-go/api/v1/api.gremlin.post_test.go
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
package v1_test
import (
diff --git a/hugegraph-client-go/api/v1/api.propertykey.create.go b/hugegraph-client-go/api/v1/api.propertykey.create.go
new file mode 100644
index 00000000..f903e8f8
--- /dev/null
+++ b/hugegraph-client-go/api/v1/api.propertykey.create.go
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, PropertyKeyCreate 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package v1
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/internal/model"
+ "io"
+ "io/ioutil"
+ "net/http"
+ "strings"
+
+ "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/api"
+)
+
+// ----- API Definition -------------------------------------------------------
+// Create a PropertyKey of HugeGraph
+//
+// See full documentation at https://hugegraph.apache.org/docs/clients/restful-api/propertykey/#121-create-a-propertykey
+func newPropertyKeyCreateFunc(t api.Transport) PropertyKeyCreate {
+ return func(o ...func(*PropertyKeyCreateRequest)) (*PropertyKeyCreateResponse, error) {
+ var r = PropertyKeyCreateRequest{}
+ for _, f := range o {
+ f(&r)
+ }
+ return r.Do(r.ctx, t)
+ }
+}
+
+type PropertyKeyCreate func(o ...func(*PropertyKeyCreateRequest)) (*PropertyKeyCreateResponse, error)
+
+type PropertyKeyCreateRequest struct {
+ Body io.Reader
+ ctx context.Context
+ reqData PropertyKeyCreateRequestData
+}
+
+type PropertyKeyCreateRequestData struct {
+ Name string `json:"name"`
+ DataType model.PropertyDataType `json:"data_type"`
+ Cardinality model.PropertyCardinality `json:"cardinality"`
+}
+
+type PropertyKeyCreateResponse struct {
+ StatusCode int `json:"-"`
+ Header http.Header `json:"-"`
+ Body io.ReadCloser `json:"-"`
+ PropertyKeyCreates PropertyKeyCreateResponseData `json:"versions"`
+}
+
+type PropertyKeyCreateResponseData struct {
+ PropertyKeyCreate string `json:"version"` // hugegraph version
+ Core string `json:"core"` // hugegraph core version
+ Gremlin string `json:"gremlin"` // hugegraph gremlin version
+ API string `json:"api"` // hugegraph api version
+}
+
+func (r PropertyKeyCreateRequest) Do(ctx context.Context, transport api.Transport) (*PropertyKeyCreateResponse, error) {
+
+ if len(r.reqData.Name) <= 0 {
+ return nil, errors.New("create property must set name")
+ }
+ if len(r.reqData.DataType) <= 0 {
+ return nil, errors.New("create property must set dataType")
+ }
+ if len(r.reqData.Cardinality) <= 0 {
+ return nil, errors.New("create property must set cardinality")
+ }
+
+ byteBody, err := json.Marshal(&r.reqData)
+ if err != nil {
+ return nil, err
+ }
+ reader := strings.NewReader(string(byteBody))
+
+ req, err := api.NewRequest("POST", fmt.Sprintf("/graphs/%s/schema/propertykeys", transport.GetConfig().Graph), reader)
+ if err != nil {
+ return nil, err
+ }
+ if ctx != nil {
+ req = req.WithContext(ctx)
+ }
+
+ res, err := transport.Perform(req)
+ if err != nil {
+ return nil, err
+ }
+
+ versionResp := &PropertyKeyCreateResponse{}
+ bytes, err := ioutil.ReadAll(res.Body)
+ if err != nil {
+ return nil, err
+ }
+ err = json.Unmarshal(bytes, versionResp)
+ if err != nil {
+ return nil, err
+ }
+ versionResp.StatusCode = res.StatusCode
+ versionResp.Header = res.Header
+ versionResp.Body = res.Body
+ return versionResp, nil
+}
+
+func (r PropertyKeyCreate) WithReqData(reqData PropertyKeyCreateRequestData) func(request *PropertyKeyCreateRequest) {
+ return func(r *PropertyKeyCreateRequest) {
+ r.reqData = reqData
+ }
+}
diff --git a/hugegraph-client-go/api/v1/api.propertykey.create_test.go b/hugegraph-client-go/api/v1/api.propertykey.create_test.go
new file mode 100644
index 00000000..6b055f34
--- /dev/null
+++ b/hugegraph-client-go/api/v1/api.propertykey.create_test.go
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package v1_test
+
+import (
+ "fmt"
+ "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go"
+ v1 "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/api/v1"
+ "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/internal/model"
+ "log"
+ "math/rand"
+ "testing"
+ "time"
+)
+
+func TestPropertyKeyCreateRequest_Do(t *testing.T) {
+ client, err := hugegraph.NewDefaultCommonClient()
+ if err != nil {
+ log.Println(err)
+ }
+ rand.Seed(time.Now().UnixNano())
+ name := fmt.Sprintf("testProperty%d", rand.Intn(99999))
+ resp, err := client.PropertyKey.PropertyKeyCreate(
+ client.PropertyKey.PropertyKeyCreate.WithReqData(
+ v1.PropertyKeyCreateRequestData{
+ Name: name,
+ DataType: model.PropertyDataTypeInt,
+ Cardinality: model.PropertyCardinalitySingle,
+ },
+ ),
+ )
+ if err != nil {
+ log.Println(err)
+ }
+
+ fmt.Println(resp)
+
+ // propertyKey delete after create
+ respDelete, err := client.PropertyKey.PropertyKeyDeleteByName(
+ client.PropertyKey.PropertyKeyDeleteByName.WithName(name),
+ )
+ if err != nil {
+ log.Println(err)
+ }
+ fmt.Println(respDelete)
+}
diff --git a/hugegraph-client-go/api/v1/api.propertykey.delete_by_name.go b/hugegraph-client-go/api/v1/api.propertykey.delete_by_name.go
new file mode 100644
index 00000000..d6a86784
--- /dev/null
+++ b/hugegraph-client-go/api/v1/api.propertykey.delete_by_name.go
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, PropertyKeyDeleteByName 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package v1
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "net/http"
+
+ "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/api"
+)
+
+// ----- API Definition -------------------------------------------------------
+// Delete PropertyKey according to name
+//
+// See full documentation at https://hugegraph.apache.org/docs/clients/restful-api/propertykey/#125-delete-propertykey-according-to-name
+func newPropertyKeyDeleteByNameFunc(t api.Transport) PropertyKeyDeleteByName {
+ return func(o ...func(*PropertyKeyDeleteByNameRequest)) (*PropertyKeyDeleteByNameResponse, error) {
+ var r = PropertyKeyDeleteByNameRequest{}
+ for _, f := range o {
+ f(&r)
+ }
+ return r.Do(r.ctx, t)
+ }
+}
+
+type PropertyKeyDeleteByName func(o ...func(*PropertyKeyDeleteByNameRequest)) (*PropertyKeyDeleteByNameResponse, error)
+
+type PropertyKeyDeleteByNameRequest struct {
+ Body io.Reader
+ ctx context.Context
+ name string
+}
+
+type PropertyKeyDeleteByNameResponse struct {
+ StatusCode int `json:"-"`
+ Header http.Header `json:"-"`
+ Body io.ReadCloser `json:"-"`
+ PropertyKeyDeleteByNames PropertyKeyDeleteByNameResponseData `json:"versions"`
+}
+
+type PropertyKeyDeleteByNameResponseData struct {
+ PropertyKeyDeleteByName string `json:"version"` // hugegraph version
+ Core string `json:"core"` // hugegraph core version
+ Gremlin string `json:"gremlin"` // hugegraph gremlin version
+ API string `json:"api"` // hugegraph api version
+}
+
+func (r PropertyKeyDeleteByNameRequest) Do(ctx context.Context, transport api.Transport) (*PropertyKeyDeleteByNameResponse, error) {
+
+ if len(r.name) <= 0 {
+ return nil, errors.New("delete by name ,please set name")
+ }
+ req, err := api.NewRequest("DELETE", fmt.Sprintf("/graphs/%s/schema/propertykeys/%s", transport.GetConfig().Graph, r.name), r.Body)
+ if err != nil {
+ return nil, err
+ }
+ if ctx != nil {
+ req = req.WithContext(ctx)
+ }
+
+ res, err := transport.Perform(req)
+ if err != nil {
+ return nil, err
+ }
+
+ versionResp := &PropertyKeyDeleteByNameResponse{}
+ bytes, err := ioutil.ReadAll(res.Body)
+ if err != nil {
+ return nil, err
+ }
+ err = json.Unmarshal(bytes, versionResp)
+ if err != nil {
+ return nil, err
+ }
+ versionResp.StatusCode = res.StatusCode
+ versionResp.Header = res.Header
+ versionResp.Body = res.Body
+ return versionResp, nil
+}
+
+func (p PropertyKeyDeleteByName) WithName(name string) func(request *PropertyKeyDeleteByNameRequest) {
+ return func(r *PropertyKeyDeleteByNameRequest) {
+ r.name = name
+ }
+}
diff --git a/hugegraph-client-go/internal/model/model.go b/hugegraph-client-go/api/v1/api.propertykey.delete_by_name_test.go
similarity index 84%
copy from hugegraph-client-go/internal/model/model.go
copy to hugegraph-client-go/api/v1/api.propertykey.delete_by_name_test.go
index 733a466b..c6735076 100644
--- a/hugegraph-client-go/internal/model/model.go
+++ b/hugegraph-client-go/api/v1/api.propertykey.delete_by_name_test.go
@@ -15,11 +15,12 @@
* under the License.
*/
-package model
+package v1_test
-// Vertex models that support generic types
-type Vertex[T any] struct {
- ID string
- Label string
- Properties T
+import (
+ "testing"
+)
+
+func TestPropertyKeyDeleteByNameRequest_Do(t *testing.T) {
+ // this test in TestPropertyKeyCreateRequest_Do
}
diff --git a/hugegraph-client-go/api/v1/api.propertykey.get_all.go b/hugegraph-client-go/api/v1/api.propertykey.get_all.go
new file mode 100644
index 00000000..4005b355
--- /dev/null
+++ b/hugegraph-client-go/api/v1/api.propertykey.get_all.go
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, PropertyKeyGetAll 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package v1
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "net/http"
+
+ "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/api"
+)
+
+// ----- API Definition -------------------------------------------------------
+// Get all PropertyKeys of HugeGraph
+//
+// See full documentation at https://hugegraph.apache.org/docs/clients/restful-api/propertykey/#123-get-all-propertykeys
+func newPropertyKeyGetAllFunc(t api.Transport) PropertyKeyGetAll {
+ return func(o ...func(*PropertyKeyGetAllRequest)) (*PropertyKeyGetAllResponse, error) {
+ var r = PropertyKeyGetAllRequest{}
+ for _, f := range o {
+ f(&r)
+ }
+ return r.Do(r.ctx, t)
+ }
+}
+
+type PropertyKeyGetAll func(o ...func(*PropertyKeyGetAllRequest)) (*PropertyKeyGetAllResponse, error)
+
+type PropertyKeyGetAllRequest struct {
+ Body io.Reader
+ ctx context.Context
+}
+
+type PropertyKeyGetAllResponse struct {
+ StatusCode int `json:"-"`
+ Header http.Header `json:"-"`
+ Body io.ReadCloser `json:"-"`
+ PropertyKeyGetAll PropertyKeyGetAllResponseData `json:"-"`
+}
+
+type PropertyKeyGetAllResponseData struct {
+ Propertykeys []struct {
+ ID int `json:"id"`
+ Name string `json:"name"`
+ DataType string `json:"data_type"`
+ Cardinality string `json:"cardinality"`
+ Properties []interface{} `json:"properties"`
+ UserData struct {
+ } `json:"user_data"`
+ } `json:"propertykeys"`
+}
+
+func (r PropertyKeyGetAllRequest) Do(ctx context.Context, transport api.Transport) (*PropertyKeyGetAllResponse, error) {
+
+ req, err := api.NewRequest("GET", fmt.Sprintf("/graphs/%s/schema/propertykeys", transport.GetConfig().Graph), r.Body)
+ if err != nil {
+ return nil, err
+ }
+ if ctx != nil {
+ req = req.WithContext(ctx)
+ }
+
+ res, err := transport.Perform(req)
+ if err != nil {
+ return nil, err
+ }
+
+ resp := &PropertyKeyGetAllResponse{}
+ bytes, err := ioutil.ReadAll(res.Body)
+ if err != nil {
+ return nil, err
+ }
+ respData := PropertyKeyGetAllResponseData{}
+ err = json.Unmarshal(bytes, &respData)
+ if err != nil {
+ return nil, err
+ }
+ resp.StatusCode = res.StatusCode
+ resp.Header = res.Header
+ resp.Body = res.Body
+ resp.PropertyKeyGetAll = respData
+ return resp, nil
+}
diff --git a/hugegraph-client-go/internal/model/model.go b/hugegraph-client-go/api/v1/api.propertykey.get_all_test.go
similarity index 64%
copy from hugegraph-client-go/internal/model/model.go
copy to hugegraph-client-go/api/v1/api.propertykey.get_all_test.go
index 733a466b..270c2c4f 100644
--- a/hugegraph-client-go/internal/model/model.go
+++ b/hugegraph-client-go/api/v1/api.propertykey.get_all_test.go
@@ -15,11 +15,23 @@
* under the License.
*/
-package model
+package v1_test
-// Vertex models that support generic types
-type Vertex[T any] struct {
- ID string
- Label string
- Properties T
+import (
+ "fmt"
+ "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go"
+ "log"
+ "testing"
+)
+
+func TestPropertyKeyGetAllRequest_Do(t *testing.T) {
+ client, err := hugegraph.NewDefaultCommonClient()
+ if err != nil {
+ log.Println(err)
+ }
+ resp, err := client.PropertyKey.PropertyKeyGetAll()
+ if err != nil {
+ log.Println(err)
+ }
+ fmt.Println(resp.PropertyKeyGetAll)
}
diff --git a/hugegraph-client-go/api/v1/api.propertykey.get_by_name.go b/hugegraph-client-go/api/v1/api.propertykey.get_by_name.go
new file mode 100644
index 00000000..13acf8a0
--- /dev/null
+++ b/hugegraph-client-go/api/v1/api.propertykey.get_by_name.go
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, PropertyKeyGetByName 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package v1
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "net/http"
+
+ "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/api"
+)
+
+// ----- API Definition -------------------------------------------------------
+// Get PropertyKey according to name of HugeGraph
+//
+// See full documentation at https://hugegraph.apache.org/docs/clients/restful-api/propertykey/#124-get-propertykey-according-to-name
+func newPropertyKeyGetByNameFunc(t api.Transport) PropertyKeyGetByName {
+ return func(o ...func(*PropertyKeyGetByNameRequest)) (*PropertyKeyGetByNameResponse, error) {
+ var r = PropertyKeyGetByNameRequest{}
+ for _, f := range o {
+ f(&r)
+ }
+ return r.Do(r.ctx, t)
+ }
+}
+
+type PropertyKeyGetByName func(o ...func(*PropertyKeyGetByNameRequest)) (*PropertyKeyGetByNameResponse, error)
+
+type PropertyKeyGetByNameRequest struct {
+ Body io.Reader
+ ctx context.Context
+ name string
+}
+
+type PropertyKeyGetByNameResponse struct {
+ StatusCode int `json:"-"`
+ Header http.Header `json:"-"`
+ Body io.ReadCloser `json:"-"`
+ PropertyKeyGetByName PropertyKeyGetByNameResponseData `json:"-"`
+}
+
+type PropertyKeyGetByNameResponseData struct {
+ ID int `json:"id"`
+ Name string `json:"name"`
+ DataType string `json:"data_type"`
+ Cardinality string `json:"cardinality"`
+ AggregateType string `json:"aggregate_type"`
+ WriteType string `json:"write_type"`
+ Properties []interface{} `json:"properties"`
+ Status string `json:"status"`
+ UserData struct {
+ Min int `json:"min"`
+ Max int `json:"max"`
+ CreateTime string `json:"~create_time"`
+ } `json:"user_data"`
+}
+
+func (r PropertyKeyGetByNameRequest) Do(ctx context.Context, transport api.Transport) (*PropertyKeyGetByNameResponse, error) {
+
+ if len(r.name) <= 0 {
+ return nil, errors.New("get_by_name must set name")
+ }
+
+ req, err := api.NewRequest("GET", fmt.Sprintf("/graphs/%s/schema/propertykeys/%s", transport.GetConfig().Graph, r.name), r.Body)
+ if err != nil {
+ return nil, err
+ }
+ if ctx != nil {
+ req = req.WithContext(ctx)
+ }
+
+ res, err := transport.Perform(req)
+ if err != nil {
+ return nil, err
+ }
+
+ resp := &PropertyKeyGetByNameResponse{}
+ bytes, err := ioutil.ReadAll(res.Body)
+ if err != nil {
+ return nil, err
+ }
+ respData := PropertyKeyGetByNameResponseData{}
+ err = json.Unmarshal(bytes, &respData)
+ if err != nil {
+ return nil, err
+ }
+ resp.StatusCode = res.StatusCode
+ resp.Header = res.Header
+ resp.Body = res.Body
+ resp.PropertyKeyGetByName = respData
+ return resp, nil
+}
+
+func (r PropertyKeyGetByName) WithName(name string) func(request *PropertyKeyGetByNameRequest) {
+ return func(r *PropertyKeyGetByNameRequest) {
+ r.name = name
+ }
+}
diff --git a/hugegraph-client-go/internal/model/model.go b/hugegraph-client-go/api/v1/api.propertykey.get_by_name_test.go
similarity index 63%
copy from hugegraph-client-go/internal/model/model.go
copy to hugegraph-client-go/api/v1/api.propertykey.get_by_name_test.go
index 733a466b..a8067598 100644
--- a/hugegraph-client-go/internal/model/model.go
+++ b/hugegraph-client-go/api/v1/api.propertykey.get_by_name_test.go
@@ -15,11 +15,23 @@
* under the License.
*/
-package model
+package v1_test
-// Vertex models that support generic types
-type Vertex[T any] struct {
- ID string
- Label string
- Properties T
+import (
+ "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go"
+ "log"
+ "testing"
+)
+
+func TestPropertyKeyGetByNameRequest_Do(t *testing.T) {
+ client, err := hugegraph.NewDefaultCommonClient()
+ if err != nil {
+ log.Println(err)
+ }
+ _, err = client.PropertyKey.PropertyKeyGetByName(
+ client.PropertyKey.PropertyKeyGetByName.WithName("price"),
+ )
+ if err != nil {
+ log.Println(err)
+ }
}
diff --git a/hugegraph-client-go/api/v1/api.schema.go b/hugegraph-client-go/api/v1/api.schema.go
new file mode 100644
index 00000000..5ae73d46
--- /dev/null
+++ b/hugegraph-client-go/api/v1/api.schema.go
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Schema 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package v1
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+ "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/hgtransport"
+ "io"
+ "io/ioutil"
+ "net/http"
+
+ "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/api"
+)
+
+// ----- API Definition -------------------------------------------------------
+// View Schema information of HugeGraph
+//
+// See full documentation at https://hugegraph.apache.org/docs/clients/restful-api/schema/#11-schema
+func newSchemaFunc(t api.Transport) Schema {
+ return func(o ...func(*SchemaRequest)) (*SchemaResponse, error) {
+ var r = SchemaRequest{}
+ for _, f := range o {
+ f(&r)
+ }
+ return r.Do(r.ctx, t)
+ }
+}
+
+type Schema func(o ...func(*SchemaRequest)) (*SchemaResponse, error)
+
+type SchemaRequest struct {
+ Body io.Reader
+ ctx context.Context
+ config hgtransport.Config
+}
+
+type SchemaResponse struct {
+ StatusCode int `json:"-"`
+ Header http.Header `json:"-"`
+ Body io.ReadCloser `json:"-"`
+ Data SchemaResponseData `json:"-"`
+}
+
+type SchemaResponseData struct {
+ Propertykeys []struct {
+ ID int `json:"id"`
+ Name string `json:"name"`
+ DataType string `json:"data_type"`
+ Cardinality string `json:"cardinality"`
+ AggregateType string `json:"aggregate_type"`
+ WriteType string `json:"write_type"`
+ Properties []interface{} `json:"properties"`
+ Status string `json:"status"`
+ UserData struct {
+ CreateTime string `json:"~create_time"`
+ } `json:"user_data"`
+ } `json:"propertykeys"`
+ Vertexlabels []struct {
+ ID int `json:"id"`
+ Name string `json:"name"`
+ IDStrategy string `json:"id_strategy"`
+ PrimaryKeys []string `json:"primary_keys"`
+ NullableKeys []interface{} `json:"nullable_keys"`
+ IndexLabels []string `json:"index_labels"`
+ Properties []string `json:"properties"`
+ Status string `json:"status"`
+ TTL int `json:"ttl"`
+ EnableLabelIndex bool `json:"enable_label_index"`
+ UserData struct {
+ CreateTime string `json:"~create_time"`
+ } `json:"user_data"`
+ } `json:"vertexlabels"`
+ Edgelabels []struct {
+ ID int `json:"id"`
+ Name string `json:"name"`
+ SourceLabel string `json:"source_label"`
+ TargetLabel string `json:"target_label"`
+ Frequency string `json:"frequency"`
+ SortKeys []interface{} `json:"sort_keys"`
+ NullableKeys []interface{} `json:"nullable_keys"`
+ IndexLabels []string `json:"index_labels"`
+ Properties []string `json:"properties"`
+ Status string `json:"status"`
+ TTL int `json:"ttl"`
+ EnableLabelIndex bool `json:"enable_label_index"`
+ UserData struct {
+ CreateTime string `json:"~create_time"`
+ } `json:"user_data"`
+ } `json:"edgelabels"`
+ Indexlabels []struct {
+ ID int `json:"id"`
+ Name string `json:"name"`
+ BaseType string `json:"base_type"`
+ BaseValue string `json:"base_value"`
+ IndexType string `json:"index_type"`
+ Fields []string `json:"fields"`
+ Status string `json:"status"`
+ UserData struct {
+ CreateTime string `json:"~create_time"`
+ } `json:"user_data"`
+ } `json:"indexlabels"`
+}
+
+func (r SchemaRequest) Do(ctx context.Context, transport api.Transport) (*SchemaResponse, error) {
+
+ req, err := api.NewRequest("GET", fmt.Sprintf("/graphs/%s/schema", transport.GetConfig().Graph), r.Body)
+ if err != nil {
+ return nil, err
+ }
+ if ctx != nil {
+ req = req.WithContext(ctx)
+ }
+
+ res, err := transport.Perform(req)
+ if err != nil {
+ return nil, err
+ }
+
+ schemaRespData := SchemaResponseData{}
+ bytes, err := ioutil.ReadAll(res.Body)
+ if err != nil {
+ return nil, err
+ }
+ err = json.Unmarshal(bytes, &schemaRespData)
+ if err != nil {
+ return nil, err
+ }
+ schemaResp := &SchemaResponse{}
+ schemaResp.StatusCode = res.StatusCode
+ schemaResp.Header = res.Header
+ schemaResp.Body = res.Body
+ schemaResp.Data = schemaRespData
+ return schemaResp, nil
+}
diff --git a/hugegraph-client-go/internal/model/model.go b/hugegraph-client-go/api/v1/api.schema_test.go
similarity index 66%
copy from hugegraph-client-go/internal/model/model.go
copy to hugegraph-client-go/api/v1/api.schema_test.go
index 733a466b..47daab74 100644
--- a/hugegraph-client-go/internal/model/model.go
+++ b/hugegraph-client-go/api/v1/api.schema_test.go
@@ -15,11 +15,23 @@
* under the License.
*/
-package model
+package v1_test
-// Vertex models that support generic types
-type Vertex[T any] struct {
- ID string
- Label string
- Properties T
+import (
+ "fmt"
+ "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go"
+ "log"
+ "testing"
+)
+
+func TestSchemaRequest_Do(t *testing.T) {
+ client, err := hugegraph.NewDefaultCommonClient()
+ if err != nil {
+ log.Println(err)
+ }
+ schema, err := client.Schema()
+ if err != nil {
+ log.Fatalln(err)
+ }
+ fmt.Println(schema.Data)
}
diff --git a/hugegraph-client-go/api/v1/api.veretx.create.go b/hugegraph-client-go/api/v1/api.veretx.create.go
index 2211ec76..8e22560d 100644
--- a/hugegraph-client-go/api/v1/api.veretx.create.go
+++ b/hugegraph-client-go/api/v1/api.veretx.create.go
@@ -14,6 +14,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
+
package v1
import (
diff --git a/hugegraph-client-go/api/v1/api.version_test.go b/hugegraph-client-go/api/v1/api.version_test.go
index 980c5158..cd3e874b 100644
--- a/hugegraph-client-go/api/v1/api.version_test.go
+++ b/hugegraph-client-go/api/v1/api.version_test.go
@@ -18,14 +18,9 @@
package v1_test
import (
- "context"
- "io"
- "reflect"
"testing"
hugegraph "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go"
- "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/api"
- v1 "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/api/v1"
)
func TestVersionRequest_Do(t *testing.T) {
@@ -34,52 +29,11 @@ func TestVersionRequest_Do(t *testing.T) {
if err != nil {
t.Errorf("NewDefaultCommonClient() error = %v", err)
}
- ctx := context.Background()
-
- type fields struct {
- Body io.Reader
- ctx context.Context
- }
- type args struct {
- ctx context.Context
- transport api.Transport
- }
- tests := []struct {
- name string
- fields fields
- args args
- want v1.VersionResponseData
- wantErr bool
- }{
-
- {
- name: "test-version",
- fields: fields{
- Body: nil,
- ctx: ctx,
- },
- args: args{
- ctx: ctx,
- transport: client.Transport,
- },
- want: v1.VersionResponseData{
- Version: "v1",
- Core: "1.0.0",
- Gremlin: "3.4.3",
- API: "0.69.0.0",
- },
- },
+ resp, err := client.Version()
+ if err != nil {
+ t.Errorf(" client.Version() error = %v", err)
}
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- got, err := client.Version()
- if (err != nil) != tt.wantErr {
- t.Errorf("Do() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- if !reflect.DeepEqual(got.Versions, tt.want) {
- t.Errorf("Do() got = %v, want %v", got.Versions, tt.want)
- }
- })
+ if resp.StatusCode != 200 {
+ t.Errorf(" client.Version() code error = %v", resp.StatusCode)
}
}
diff --git a/hugegraph-client-go/internal/model/model.go b/hugegraph-client-go/internal/model/model.go
index 733a466b..c4b3ab8b 100644
--- a/hugegraph-client-go/internal/model/model.go
+++ b/hugegraph-client-go/internal/model/model.go
@@ -17,6 +17,16 @@
package model
+const (
+ PropertyDataTypeInt PropertyDataType = "INT" // data_type int
+ PropertyCardinalitySingle PropertyCardinality = "SINGLE" // cardinality single
+ ActionAppend Action = "append" // append action
+)
+
+type PropertyDataType string
+type PropertyCardinality string
+type Action string
+
// Vertex models that support generic types
type Vertex[T any] struct {
ID string
(incubator-hugegraph-toolchain) 02/02: add apis
Posted by ji...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jin pushed a commit to branch tmp-go
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph-toolchain.git
commit 3f71ec0c59580f1a57f3eb168160853f14985a50
Author: izliang <iz...@qq.com>
AuthorDate: Wed Nov 1 13:00:15 2023 +0800
add apis
Change-Id: Icfee0decd5a6753766c62551f7cf643e522fa75f
---
hugegraph-client-go/api/api.resquest.go | 11 +-
hugegraph-client-go/api/v1/api._.go | 6 +
hugegraph-client-go/api/v1/api.gremlin.get.go | 120 +++++++++++++++++
hugegraph-client-go/api/v1/api.gremlin.get_test.go | 58 +++++++++
hugegraph-client-go/api/v1/api.gremlin.post.go | 2 +-
.../api/v1/api.propertykey.create.go | 2 +-
.../api/v1/api.propertykey.delete_by_name.go | 2 +-
.../api/v1/api.propertykey.get_all.go | 2 +-
.../api/v1/api.propertykey.get_by_name.go | 2 +-
.../api/v1/api.propertykey.update_userdata.go | 144 +++++++++++++++++++++
.../api/v1/api.propertykey.update_userdata_test.go | 54 ++++++++
hugegraph-client-go/api/v1/api.schema.go | 2 +-
hugegraph-client-go/api/v1/api.veretx.create.go | 2 +-
hugegraph-client-go/api/v1/api.version.go | 2 +-
14 files changed, 399 insertions(+), 10 deletions(-)
diff --git a/hugegraph-client-go/api/api.resquest.go b/hugegraph-client-go/api/api.resquest.go
index 6f14e80a..9d08acfe 100644
--- a/hugegraph-client-go/api/api.resquest.go
+++ b/hugegraph-client-go/api/api.resquest.go
@@ -41,10 +41,17 @@ type Request interface {
}
// newRequest creates an HTTP request.
-func NewRequest(method, path string, body io.Reader) (*http.Request, error) {
+func NewRequest(method, path string, params *url.Values, body io.Reader) (*http.Request, error) {
+
+ u := &url.URL{
+ Path: path,
+ }
+ if params != nil {
+ u.RawQuery = params.Encode()
+ }
r := http.Request{
Method: method,
- URL: &url.URL{Path: path},
+ URL: u,
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,
diff --git a/hugegraph-client-go/api/v1/api._.go b/hugegraph-client-go/api/v1/api._.go
index 759791a4..a68e0359 100644
--- a/hugegraph-client-go/api/v1/api._.go
+++ b/hugegraph-client-go/api/v1/api._.go
@@ -29,6 +29,7 @@ type APIV1 struct {
Create
}
Gremlin struct {
+ GremlinGet
GremlinPost
}
PropertyKey struct {
@@ -36,6 +37,7 @@ type APIV1 struct {
PropertyKeyGetByName
PropertyKeyCreate
PropertyKeyDeleteByName
+ PropertyKeyUpdateUserdata
}
}
@@ -50,8 +52,10 @@ func New(t api.Transport) *APIV1 {
Create: newCreateFunc(t),
},
Gremlin: struct {
+ GremlinGet
GremlinPost
}{
+ GremlinGet: newGremlinGetFunc(t),
GremlinPost: newGremlinPostFunc(t),
},
PropertyKey: struct {
@@ -59,11 +63,13 @@ func New(t api.Transport) *APIV1 {
PropertyKeyGetByName
PropertyKeyCreate
PropertyKeyDeleteByName
+ PropertyKeyUpdateUserdata
}{
PropertyKeyGetAll: newPropertyKeyGetAllFunc(t),
PropertyKeyGetByName: newPropertyKeyGetByNameFunc(t),
PropertyKeyCreate: newPropertyKeyCreateFunc(t),
PropertyKeyDeleteByName: newPropertyKeyDeleteByNameFunc(t),
+ PropertyKeyUpdateUserdata: newPropertyKeyUpdateUserdataFunc(t),
},
}
}
diff --git a/hugegraph-client-go/api/v1/api.gremlin.get.go b/hugegraph-client-go/api/v1/api.gremlin.get.go
new file mode 100644
index 00000000..a6e148be
--- /dev/null
+++ b/hugegraph-client-go/api/v1/api.gremlin.get.go
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package v1
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/api"
+ "io"
+ "io/ioutil"
+ "net/http"
+ url2 "net/url"
+)
+
+// ----- API Definition -------------------------------------------------------
+// View Create a vertex
+//
+// See full documentation at https://hugegraph.apache.org/docs/clients/restful-api/vertex/#211-create-a-vertex
+func newGremlinGetFunc(t api.Transport) GremlinGet {
+ return func(o ...func(*GremlinGetRequest)) (*GremlinGetResponse, error) {
+ var r = GremlinGetRequest{}
+ for _, f := range o {
+ f(&r)
+ }
+ return r.Do(r.ctx, t)
+ }
+}
+
+type GremlinGet func(o ...func(*GremlinGetRequest)) (*GremlinGetResponse, error)
+
+type GremlinGetRequest struct {
+ ctx context.Context
+ gremlin string
+ bindings map[string]string
+ language string
+ aliases map[string]string
+}
+
+type GremlinGetResponse struct {
+ StatusCode int `json:"-"`
+ Header http.Header `json:"-"`
+ Body io.ReadCloser `json:"-"`
+}
+
+func (g GremlinGetRequest) Do(ctx context.Context, transport api.Transport) (*GremlinGetResponse, error) {
+
+ url := "/gremlin"
+ params := &url2.Values{}
+ if len(g.gremlin) <= 0 {
+ return nil, errors.New("please set gremlin")
+ } else {
+ params.Add("gremlin", g.gremlin)
+ }
+ if len(g.language) > 0 {
+ params.Add("language", g.language)
+ }
+
+ if g.aliases != nil && len(g.aliases) >= 0 {
+ aliasesJsonStr, err := json.Marshal(g.aliases)
+ if err != nil {
+ return nil, err
+ }
+ params.Add("aliases", string(aliasesJsonStr))
+ }
+
+ if g.bindings != nil && len(g.bindings) >= 0 {
+ bindingsJsonStr, err := json.Marshal(g.bindings)
+ if err != nil {
+ return nil, err
+ }
+ params.Add("bindings", string(bindingsJsonStr))
+ }
+
+ req, err := api.NewRequest("GET", url, params, nil)
+ if err != nil {
+ return nil, err
+ }
+ if ctx != nil {
+ req = req.WithContext(ctx)
+ }
+
+ res, err := transport.Perform(req)
+ if err != nil {
+ return nil, err
+ }
+
+ bytes, err := ioutil.ReadAll(res.Body)
+ if err != nil {
+ return nil, err
+ }
+
+ fmt.Println(string(bytes))
+
+ gremlinGetResponse := &GremlinGetResponse{}
+ gremlinGetResponse.StatusCode = res.StatusCode
+ return gremlinGetResponse, nil
+}
+
+func (g GremlinGet) WithGremlin(gremlin string) func(request *GremlinGetRequest) {
+ return func(r *GremlinGetRequest) {
+ r.gremlin = gremlin
+ }
+}
diff --git a/hugegraph-client-go/api/v1/api.gremlin.get_test.go b/hugegraph-client-go/api/v1/api.gremlin.get_test.go
new file mode 100644
index 00000000..de7de4c5
--- /dev/null
+++ b/hugegraph-client-go/api/v1/api.gremlin.get_test.go
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package v1_test
+
+import (
+ "fmt"
+ "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go"
+ "io/ioutil"
+ "log"
+ "net/http"
+ "testing"
+)
+
+func TestGremlinGetRequest_Do(t *testing.T) {
+
+ client, err := hugegraph.NewDefaultCommonClient()
+ if err != nil {
+ log.Println(err)
+ }
+ resp, err := client.Gremlin.GremlinGet(
+ client.Gremlin.GremlinGet.WithGremlin("hugegraph.traversal().V().limit(3)"),
+ )
+ if err != nil {
+ log.Fatalln(err)
+ }
+ fmt.Println(resp.Body)
+
+ t1()
+}
+
+func t1() {
+ url := "http://82.157.70.33:18080/gremlin?gremlin=hugegraph.traversal().V().limit(3)"
+
+ req, _ := http.NewRequest("GET", url, nil)
+
+ res, _ := http.DefaultClient.Do(req)
+
+ defer res.Body.Close()
+ body, _ := ioutil.ReadAll(res.Body)
+
+ fmt.Println(res)
+ fmt.Println(string(body))
+}
\ No newline at end of file
diff --git a/hugegraph-client-go/api/v1/api.gremlin.post.go b/hugegraph-client-go/api/v1/api.gremlin.post.go
index 17ccb6a5..ed02249a 100644
--- a/hugegraph-client-go/api/v1/api.gremlin.post.go
+++ b/hugegraph-client-go/api/v1/api.gremlin.post.go
@@ -115,7 +115,7 @@ func (g GremlinPostRequest) Do(ctx context.Context, transport api.Transport) (*G
}
reader := strings.NewReader(string(byteBody))
- req, _ := api.NewRequest("POST", "/gremlin", reader)
+ req, _ := api.NewRequest("POST", "/gremlin", nil, reader)
if ctx != nil {
req = req.WithContext(ctx)
diff --git a/hugegraph-client-go/api/v1/api.propertykey.create.go b/hugegraph-client-go/api/v1/api.propertykey.create.go
index f903e8f8..02f62770 100644
--- a/hugegraph-client-go/api/v1/api.propertykey.create.go
+++ b/hugegraph-client-go/api/v1/api.propertykey.create.go
@@ -91,7 +91,7 @@ func (r PropertyKeyCreateRequest) Do(ctx context.Context, transport api.Transpor
}
reader := strings.NewReader(string(byteBody))
- req, err := api.NewRequest("POST", fmt.Sprintf("/graphs/%s/schema/propertykeys", transport.GetConfig().Graph), reader)
+ req, err := api.NewRequest("POST", fmt.Sprintf("/graphs/%s/schema/propertykeys", transport.GetConfig().Graph), nil, reader)
if err != nil {
return nil, err
}
diff --git a/hugegraph-client-go/api/v1/api.propertykey.delete_by_name.go b/hugegraph-client-go/api/v1/api.propertykey.delete_by_name.go
index d6a86784..b85cd5f3 100644
--- a/hugegraph-client-go/api/v1/api.propertykey.delete_by_name.go
+++ b/hugegraph-client-go/api/v1/api.propertykey.delete_by_name.go
@@ -70,7 +70,7 @@ func (r PropertyKeyDeleteByNameRequest) Do(ctx context.Context, transport api.Tr
if len(r.name) <= 0 {
return nil, errors.New("delete by name ,please set name")
}
- req, err := api.NewRequest("DELETE", fmt.Sprintf("/graphs/%s/schema/propertykeys/%s", transport.GetConfig().Graph, r.name), r.Body)
+ req, err := api.NewRequest("DELETE", fmt.Sprintf("/graphs/%s/schema/propertykeys/%s", transport.GetConfig().Graph, r.name), nil, r.Body)
if err != nil {
return nil, err
}
diff --git a/hugegraph-client-go/api/v1/api.propertykey.get_all.go b/hugegraph-client-go/api/v1/api.propertykey.get_all.go
index 4005b355..28735269 100644
--- a/hugegraph-client-go/api/v1/api.propertykey.get_all.go
+++ b/hugegraph-client-go/api/v1/api.propertykey.get_all.go
@@ -70,7 +70,7 @@ type PropertyKeyGetAllResponseData struct {
func (r PropertyKeyGetAllRequest) Do(ctx context.Context, transport api.Transport) (*PropertyKeyGetAllResponse, error) {
- req, err := api.NewRequest("GET", fmt.Sprintf("/graphs/%s/schema/propertykeys", transport.GetConfig().Graph), r.Body)
+ req, err := api.NewRequest("GET", fmt.Sprintf("/graphs/%s/schema/propertykeys", transport.GetConfig().Graph), nil, r.Body)
if err != nil {
return nil, err
}
diff --git a/hugegraph-client-go/api/v1/api.propertykey.get_by_name.go b/hugegraph-client-go/api/v1/api.propertykey.get_by_name.go
index 13acf8a0..2390f274 100644
--- a/hugegraph-client-go/api/v1/api.propertykey.get_by_name.go
+++ b/hugegraph-client-go/api/v1/api.propertykey.get_by_name.go
@@ -80,7 +80,7 @@ func (r PropertyKeyGetByNameRequest) Do(ctx context.Context, transport api.Trans
return nil, errors.New("get_by_name must set name")
}
- req, err := api.NewRequest("GET", fmt.Sprintf("/graphs/%s/schema/propertykeys/%s", transport.GetConfig().Graph, r.name), r.Body)
+ req, err := api.NewRequest("GET", fmt.Sprintf("/graphs/%s/schema/propertykeys/%s", transport.GetConfig().Graph, r.name), nil, r.Body)
if err != nil {
return nil, err
}
diff --git a/hugegraph-client-go/api/v1/api.propertykey.update_userdata.go b/hugegraph-client-go/api/v1/api.propertykey.update_userdata.go
new file mode 100644
index 00000000..89711355
--- /dev/null
+++ b/hugegraph-client-go/api/v1/api.propertykey.update_userdata.go
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, PropertyKeyUpdateUserdata 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package v1
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/internal/model"
+ "io"
+ "io/ioutil"
+ "net/http"
+ "net/url"
+ "strings"
+
+ "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/api"
+)
+
+// ----- API Definition -------------------------------------------------------
+// Add or Remove userdata for an existing PropertyKey
+//
+// See full documentation at https://hugegraph.apache.org/docs/clients/restful-api/propertykey/#122-add-or-remove-userdata-for-an-existing-propertykey
+func newPropertyKeyUpdateUserdataFunc(t api.Transport) PropertyKeyUpdateUserdata {
+ return func(o ...func(*PropertyKeyUpdateUserdataRequest)) (*PropertyKeyUpdateUserdataResponse, error) {
+ var r = PropertyKeyUpdateUserdataRequest{}
+ for _, f := range o {
+ f(&r)
+ }
+ return r.Do(r.ctx, t)
+ }
+}
+
+type PropertyKeyUpdateUserdata func(o ...func(*PropertyKeyUpdateUserdataRequest)) (*PropertyKeyUpdateUserdataResponse, error)
+
+type PropertyKeyUpdateUserdataRequest struct {
+ Body io.Reader
+ ctx context.Context
+ reqData PropertyKeyUpdateUserdataRequestData
+}
+
+type PropertyKeyUpdateUserdataRequestData struct {
+ Action model.Action `json:"-"`
+ Name string `json:"name"`
+ UserData struct {
+ Min int `json:"min"`
+ Max int `json:"max"`
+ } `json:"user_data"`
+}
+
+type PropertyKeyUpdateUserdataResponse struct {
+ StatusCode int `json:"-"`
+ Header http.Header `json:"-"`
+ Body io.ReadCloser `json:"-"`
+ PropertyKeyUpdateUserdata PropertyKeyUpdateUserdataResponseData `json:"-"`
+}
+
+type PropertyKeyUpdateUserdataResponseData struct {
+ PropertyKey struct {
+ ID int `json:"id"`
+ Name string `json:"name"`
+ DataType string `json:"data_type"`
+ Cardinality string `json:"cardinality"`
+ AggregateType string `json:"aggregate_type"`
+ WriteType string `json:"write_type"`
+ Properties []interface{} `json:"properties"`
+ Status string `json:"status"`
+ UserData struct {
+ Min int `json:"min"`
+ Max int `json:"max"`
+ CreateTime string `json:"~create_time"`
+ } `json:"user_data"`
+ } `json:"property_key"`
+ TaskID int `json:"task_id"`
+}
+
+func (r PropertyKeyUpdateUserdataRequest) Do(ctx context.Context, transport api.Transport) (*PropertyKeyUpdateUserdataResponse, error) {
+
+ params := &url.Values{}
+ if len(r.reqData.Action) <= 0 {
+ return nil, errors.New("property update userdata must set action")
+ } else {
+ params.Add("action", string(r.reqData.Action))
+ }
+ if len(r.reqData.Name) <= 0 {
+ return nil, errors.New("property update userdata must set name")
+ }
+
+ byteBody, err := json.Marshal(&r.reqData)
+ if err != nil {
+ return nil, err
+ }
+ reader := strings.NewReader(string(byteBody))
+
+ req, err := api.NewRequest("PUT", fmt.Sprintf("/graphs/%s/schema/propertykeys/%s", transport.GetConfig().Graph, r.reqData.Name), params, reader)
+ if err != nil {
+ return nil, err
+ }
+ if ctx != nil {
+ req = req.WithContext(ctx)
+ }
+
+ res, err := transport.Perform(req)
+ if err != nil {
+ return nil, err
+ }
+
+ resp := &PropertyKeyUpdateUserdataResponse{}
+ bytes, err := ioutil.ReadAll(res.Body)
+ if err != nil {
+ return nil, err
+ }
+ respData := PropertyKeyUpdateUserdataResponseData{}
+ err = json.Unmarshal(bytes, &respData)
+ if err != nil {
+ return nil, err
+ }
+ resp.StatusCode = res.StatusCode
+ resp.Header = res.Header
+ resp.Body = res.Body
+ resp.PropertyKeyUpdateUserdata = respData
+ return resp, nil
+}
+
+func (r PropertyKeyUpdateUserdata) WithReqData(reqData PropertyKeyUpdateUserdataRequestData) func(request *PropertyKeyUpdateUserdataRequest) {
+ return func(r *PropertyKeyUpdateUserdataRequest) {
+ r.reqData = reqData
+ }
+}
diff --git a/hugegraph-client-go/api/v1/api.propertykey.update_userdata_test.go b/hugegraph-client-go/api/v1/api.propertykey.update_userdata_test.go
new file mode 100644
index 00000000..a056a83d
--- /dev/null
+++ b/hugegraph-client-go/api/v1/api.propertykey.update_userdata_test.go
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package v1_test
+
+import (
+ "fmt"
+ "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go"
+ v1 "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/api/v1"
+ "github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/internal/model"
+ "log"
+ "testing"
+)
+
+func TestPropertyKeyUpdateUserdataRequest_Do(t *testing.T) {
+ client, err := hugegraph.NewDefaultCommonClient()
+ if err != nil {
+ log.Println(err)
+ }
+ resp, err := client.PropertyKey.PropertyKeyUpdateUserdata(
+ client.PropertyKey.PropertyKeyUpdateUserdata.WithReqData(
+ v1.PropertyKeyUpdateUserdataRequestData{
+ Action: model.ActionAppend,
+ Name: "age",
+ UserData: struct {
+ Min int `json:"min"`
+ Max int `json:"max"`
+ }(struct {
+ Min int
+ Max int
+ }{Min: 0, Max: 101}),
+ },
+ ),
+ )
+ if err != nil {
+ log.Println(err)
+ }
+
+ fmt.Println(resp)
+}
diff --git a/hugegraph-client-go/api/v1/api.schema.go b/hugegraph-client-go/api/v1/api.schema.go
index 5ae73d46..f1a95ba0 100644
--- a/hugegraph-client-go/api/v1/api.schema.go
+++ b/hugegraph-client-go/api/v1/api.schema.go
@@ -120,7 +120,7 @@ type SchemaResponseData struct {
func (r SchemaRequest) Do(ctx context.Context, transport api.Transport) (*SchemaResponse, error) {
- req, err := api.NewRequest("GET", fmt.Sprintf("/graphs/%s/schema", transport.GetConfig().Graph), r.Body)
+ req, err := api.NewRequest("GET", fmt.Sprintf("/graphs/%s/schema", transport.GetConfig().Graph), nil, r.Body)
if err != nil {
return nil, err
}
diff --git a/hugegraph-client-go/api/v1/api.veretx.create.go b/hugegraph-client-go/api/v1/api.veretx.create.go
index 8e22560d..3fbbd4c8 100644
--- a/hugegraph-client-go/api/v1/api.veretx.create.go
+++ b/hugegraph-client-go/api/v1/api.veretx.create.go
@@ -79,7 +79,7 @@ func (r CreateRequest) Do(ctx context.Context, transport api.Transport) (*Create
url = fmt.Sprintf("/graphs/%s/graph/vertices", config.Graph)
}
- req, err := api.NewRequest("POST", url, r.Body)
+ req, err := api.NewRequest("POST", url,nil, r.Body)
if err != nil {
return nil, err
}
diff --git a/hugegraph-client-go/api/v1/api.version.go b/hugegraph-client-go/api/v1/api.version.go
index e2237025..60507367 100644
--- a/hugegraph-client-go/api/v1/api.version.go
+++ b/hugegraph-client-go/api/v1/api.version.go
@@ -66,7 +66,7 @@ type VersionResponseData struct {
func (r VersionRequest) Do(ctx context.Context, transport api.Transport) (*VersionResponse, error) {
- req, err := api.NewRequest("GET", "/versions", r.Body)
+ req, err := api.NewRequest("GET", "/versions", nil,r.Body)
if err != nil {
return nil, err
}