Skip to content

Commit 51e35e7

Browse files
committed
fix v1 v3 api
优化v1和v3版本的client和api
1 parent 959d581 commit 51e35e7

23 files changed

+583
-112
lines changed

hgapi/api.vertex.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

hgapi/hgapi.resquest.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ var (
1919
)
2020

2121
// Request defines the API request.
22-
//
2322
type Request interface {
2423
Do(ctx context.Context, transport Transport) (*Response, error)
2524
}
2625

2726
// newRequest creates an HTTP request.
28-
//
29-
func newRequest(method, path string, body io.Reader) (*http.Request, error) {
27+
func NewRequest(method, path string, body io.Reader) (*http.Request, error) {
3028
r := http.Request{
3129
Method: method,
3230
URL: &url.URL{Path: path},

hgapi/api._.go renamed to hgapi/v1/api._.go

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
package hgapi
1+
package v1
22

33
import (
44
"context"
55
"encoding/json"
66
"errors"
7+
"hugegraph/hgapi"
78
"io"
89
"io/ioutil"
910
"net/http"
@@ -16,7 +17,7 @@ import (
1617
//
1718
// See full documentation at https://hugegraph.apache.org/cn/docs/clients/restful-api/gremlin/#811-%E5%90%91hugegraphserver%E5%8F%91%E9%80%81gremlin%E8%AF%AD%E5%8F%A5get%E5%90%8C%E6%AD%A5%E6%89%A7%E8%A1%8C
1819
//
19-
func newGremlinGetFunc(t Transport) GremlinGet {
20+
func newGremlinGetFunc(t hgapi.Transport) GremlinGet {
2021
return func(o ...func(*GremlinGetRequest)) (*GremlinGetResponse, error) {
2122
var r = GremlinGetRequest{}
2223
for _, f := range o {
@@ -44,13 +45,13 @@ type GremlinGetResponse struct {
4445
Body io.ReadCloser `json:"-"`
4546
}
4647

47-
func (r GremlinGetRequest) Do(ctx context.Context, transport Transport) (*GremlinGetResponse, error) {
48+
func (r GremlinGetRequest) Do(ctx context.Context, transport hgapi.Transport) (*GremlinGetResponse, error) {
4849

4950
if len(r.GremlinGet.Gremlin) < 1 {
5051
return nil, errors.New("GremlinGetRequest param error , gremlin is empty")
5152
}
5253

53-
req, _ := newRequest("GET", "/gremlin", r.Body)
54+
req, _ := hgapi.NewRequest("GET", "/gremlin", r.Body)
5455

5556
params := url.Values{}
5657
if len(r.GremlinGet.Gremlin) > 0 {
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package hgapi
1+
package v1
22

33
import (
44
"context"
55
"encoding/json"
66
"errors"
77
_ "fmt"
8+
"hugegraph/hgapi"
89
"io"
910
"io/ioutil"
1011
"net/http"
@@ -18,7 +19,7 @@ import (
1819
//
1920
// See full documentation at https://hugegraph.apache.org/cn/docs/clients/restful-api/gremlin/#811-%E5%90%91hugegraphserver%E5%8F%91%E9%80%81gremlin%E8%AF%AD%E5%8F%A5get%E5%90%8C%E6%AD%A5%E6%89%A7%E8%A1%8C
2021
//
21-
func newGremlinPostFunc(t Transport) GremlinPost {
22+
func newGremlinPostFunc(t hgapi.Transport) GremlinPost {
2223
return func(o ...func(*GremlinPostRequest)) (*GremlinPostResponse, error) {
2324
var r = GremlinPostRequest{}
2425
for _, f := range o {
@@ -72,7 +73,7 @@ type GremlinPostResponseData struct {
7273
Trace []string `json:"trace,omitempty"`
7374
}
7475

75-
func (r GremlinPostRequest) Do(ctx context.Context, transport Transport) (*GremlinPostResponse, error) {
76+
func (r GremlinPostRequest) Do(ctx context.Context, transport hgapi.Transport) (*GremlinPostResponse, error) {
7677

7778
if len(r.GremlinPost.Gremlin) < 1 {
7879
return nil, errors.New("GremlinPostRequest param error , gremlin is empty")
@@ -102,7 +103,7 @@ func (r GremlinPostRequest) Do(ctx context.Context, transport Transport) (*Greml
102103

103104
reader := strings.NewReader(string(byteBody)) // 转化为reader
104105

105-
req, _ := newRequest("POST", "/gremlin", reader)
106+
req, _ := hgapi.NewRequest("POST", "/gremlin", reader)
106107

107108
if ctx != nil {
108109
req = req.WithContext(ctx)
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package hgapi
1+
package v1
22

33
import (
44
"context"
55
"encoding/json"
6-
"hugegraph/internal/model"
6+
"hugegraph/hgapi"
77
"io"
88
"io/ioutil"
99
"net/http"
@@ -38,7 +38,7 @@ const (
3838
//
3939
// See full documentation https://hugegraph.apache.org/cn/docs/clients/restful-api/propertykey/#121-%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA-propertykey
4040
//
41-
func newPropertyKeysCreateFunc(t Transport) PropertyKeysCreate {
41+
func newPropertyKeysCreateFunc(t hgapi.Transport) PropertyKeysCreate {
4242
return func(o ...func(*PropertyKeysCreateRequest)) (*PropertyKeysCreateResponse, error) {
4343
var r = PropertyKeysCreateRequest{}
4444
for _, f := range o {
@@ -77,15 +77,15 @@ type PropertyKeysCreateResponse struct {
7777
TaskID int `json:"task_id"`
7878
}
7979

80-
func (r PropertyKeysCreateRequest) Do(ctx context.Context, transport Transport) (*PropertyKeysCreateResponse, error) {
80+
func (r PropertyKeysCreateRequest) Do(ctx context.Context, transport hgapi.Transport) (*PropertyKeysCreateResponse, error) {
8181

8282
bytes, err := json.Marshal(r)
8383
if err != nil {
8484
return nil, err
8585
}
8686
byteBody, _ := json.Marshal(&r) // 序列化
8787
reader := strings.NewReader(string(byteBody)) // 转化为reader
88-
req, _ := newRequest("POST", model.UrlPrefix+"/graphs/${GRAPH_NAME}/schema/propertykeys", reader)
88+
req, _ := hgapi.NewRequest("POST", "/graphs/${GRAPH_NAME}/schema/propertykeys", reader)
8989

9090
if ctx != nil {
9191
req = req.WithContext(ctx)

hgapi/api.property_keys.delete_by_name.go renamed to hgapi/v1/api.property_keys.delete_by_name.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package hgapi
1+
package v1
22

33
import (
44
"context"
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"hugegraph/hgapi"
89
"hugegraph/internal/model"
910
"io"
1011
"io/ioutil"
@@ -17,7 +18,7 @@ import (
1718
//
1819
// See full documentation https://hugegraph.apache.org/cn/docs/clients/restful-api/propertykey/#125-%E6%A0%B9%E6%8D%AEname%E5%88%A0%E9%99%A4propertykey
1920
//
20-
func newPropertyKeysDeleteByNameFunc(t Transport) PropertyKeysDeleteByName {
21+
func newPropertyKeysDeleteByNameFunc(t hgapi.Transport) PropertyKeysDeleteByName {
2122
return func(o ...func(*PropertyKeysDeleteByNameRequest)) (*PropertyKeysDeleteByNameResponse, error) {
2223
var r = PropertyKeysDeleteByNameRequest{}
2324
for _, f := range o {
@@ -41,13 +42,13 @@ type PropertyKeysDeleteByNameResponse struct {
4142
Body io.ReadCloser `json:"-"`
4243
}
4344

44-
func (r PropertyKeysDeleteByNameRequest) Do(ctx context.Context, transport Transport) (*PropertyKeysDeleteByNameResponse, error) {
45+
func (r PropertyKeysDeleteByNameRequest) Do(ctx context.Context, transport hgapi.Transport) (*PropertyKeysDeleteByNameResponse, error) {
4546

4647
if len(r.Name) < 1 {
4748
return nil, errors.New("PropertyKeysDeleteByNameRequest Param error, name is not empty")
4849
}
4950

50-
req, _ := newRequest("DELETE", fmt.Sprintf(model.UrlPrefix+"/graphs/${GRAPH_NAME}/schema/propertykeys/%s", r.Name), r.Body)
51+
req, _ := hgapi.NewRequest("DELETE", fmt.Sprintf(model.UrlPrefix+"/graphs/${GRAPH_NAME}/schema/propertykeys/%s", r.Name), r.Body)
5152

5253
if ctx != nil {
5354
req = req.WithContext(ctx)
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package hgapi
1+
package v1
22

33
import (
44
"context"
55
"encoding/json"
6+
"hugegraph/hgapi"
67
"hugegraph/internal/model"
78
"io"
89
"io/ioutil"
@@ -15,7 +16,7 @@ import (
1516
//
1617
// See full documentation https://hugegraph.apache.org/cn/docs/clients/restful-api/propertykey/#123-%E8%8E%B7%E5%8F%96%E6%89%80%E6%9C%89%E7%9A%84-propertykey
1718
//
18-
func newPropertyKeysGetFunc(t Transport) PropertyKeysGet {
19+
func newPropertyKeysGetFunc(t hgapi.Transport) PropertyKeysGet {
1920
return func(o ...func(*PropertyKeysGetRequest)) (*PropertyKeysGetResponse, error) {
2021
var r = PropertyKeysGetRequest{}
2122
for _, f := range o {
@@ -51,9 +52,9 @@ type PropertyKeysGetResponse struct {
5152
} `json:"propertykeys"`
5253
}
5354

54-
func (r PropertyKeysGetRequest) Do(ctx context.Context, transport Transport) (*PropertyKeysGetResponse, error) {
55+
func (r PropertyKeysGetRequest) Do(ctx context.Context, transport hgapi.Transport) (*PropertyKeysGetResponse, error) {
5556

56-
req, _ := newRequest("GET", model.UrlPrefix+"/graphs/${GRAPH_NAME}/schema/propertykeys", r.Body)
57+
req, _ := hgapi.NewRequest("GET", model.UrlPrefix+"/graphs/${GRAPH_NAME}/schema/propertykeys", r.Body)
5758

5859
if ctx != nil {
5960
req = req.WithContext(ctx)
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package hgapi
1+
package v1
22

33
import (
44
"context"
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"hugegraph/hgapi"
89
"hugegraph/internal/model"
910
"io"
1011
"io/ioutil"
@@ -17,7 +18,7 @@ import (
1718
//
1819
// See full documentation https://hugegraph.apache.org/cn/docs/clients/restful-api/propertykey/#124-%E6%A0%B9%E6%8D%AEname%E8%8E%B7%E5%8F%96propertykey
1920
//
20-
func newPropertyKeysGetByNameFunc(t Transport) PropertyKeysGetByName {
21+
func newPropertyKeysGetByNameFunc(t hgapi.Transport) PropertyKeysGetByName {
2122
return func(o ...func(*PropertyKeysGetByNameRequest)) (*PropertyKeysGetByNameResponse, error) {
2223
var r = PropertyKeysGetByNameRequest{}
2324
for _, f := range o {
@@ -55,13 +56,13 @@ type PropertyKeysGetByNameData struct {
5556
} `json:"user_data"`
5657
}
5758

58-
func (r PropertyKeysGetByNameRequest) Do(ctx context.Context, transport Transport) (*PropertyKeysGetByNameResponse, error) {
59+
func (r PropertyKeysGetByNameRequest) Do(ctx context.Context, transport hgapi.Transport) (*PropertyKeysGetByNameResponse, error) {
5960

6061
if len(r.Name) < 1 {
6162
return nil, errors.New("PropertyKeysGetByNameRequest Param error, name is not empty")
6263
}
6364

64-
req, _ := newRequest("GET", fmt.Sprintf(model.UrlPrefix+"/graphs/${GRAPH_NAME}/schema/propertykeys/%s", r.Name), r.Body)
65+
req, _ := hgapi.NewRequest("GET", fmt.Sprintf(model.UrlPrefix+"/graphs/${GRAPH_NAME}/schema/propertykeys/%s", r.Name), r.Body)
6566

6667
if ctx != nil {
6768
req = req.WithContext(ctx)

hgapi/api.property_keys.update_userdata.go renamed to hgapi/v1/api.property_keys.update_userdata.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package hgapi
1+
package v1
22

33
import (
44
"context"
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"hugegraph/hgapi"
89
"hugegraph/internal/model"
910
"io/ioutil"
1011
"net/http"
@@ -24,7 +25,7 @@ const (
2425
//
2526
// See full documentation https://hugegraph.apache.org/cn/docs/clients/restful-api/propertykey/#122-%E4%B8%BA%E5%B7%B2%E5%AD%98%E5%9C%A8%E7%9A%84-propertykey-%E6%B7%BB%E5%8A%A0%E6%88%96%E7%A7%BB%E9%99%A4-userdata
2627
//
27-
func newPropertyKeysUpdateUserdataFunc(t Transport) PropertyKeysUpdateUserdata {
28+
func newPropertyKeysUpdateUserdataFunc(t hgapi.Transport) PropertyKeysUpdateUserdata {
2829
return func(o ...func(*PropertyKeysUpdateUserdataRequest)) (*PropertyKeysUpdateUserdataResponse, error) {
2930
var r = PropertyKeysUpdateUserdataRequest{}
3031
for _, f := range o {
@@ -73,7 +74,7 @@ type PropertyKeysUpdateUserdataData struct {
7374
TaskID int `json:"task_id"`
7475
}
7576

76-
func (r PropertyKeysUpdateUserdataRequest) Do(ctx context.Context, transport Transport) (*PropertyKeysUpdateUserdataResponse, error) {
77+
func (r PropertyKeysUpdateUserdataRequest) Do(ctx context.Context, transport hgapi.Transport) (*PropertyKeysUpdateUserdataResponse, error) {
7778

7879
if len(r.Name) < 1 {
7980
return nil, errors.New("PropertyKeysUpdateUserdataRequest Param error, name is empty")
@@ -90,7 +91,7 @@ func (r PropertyKeysUpdateUserdataRequest) Do(ctx context.Context, transport Tra
9091
byteBody, _ := json.Marshal(&r) // 序列化
9192
reader := strings.NewReader(string(byteBody)) // 转化为reader
9293

93-
req, _ := newRequest("PUT", fmt.Sprintf(model.UrlPrefix+"/graphs/${GRAPH_NAME}/schema/propertykeys/%s?action=%s", r.Name, r.Action), reader)
94+
req, _ := hgapi.NewRequest("PUT", fmt.Sprintf(model.UrlPrefix+"/graphs/${GRAPH_NAME}/schema/propertykeys/%s?action=%s", r.Name, r.Action), reader)
9495

9596
if ctx != nil {
9697
req = req.WithContext(ctx)

0 commit comments

Comments
 (0)