Skip to content

Commit 959d581

Browse files
committed
优化非法文件
1 parent b2742a9 commit 959d581

21 files changed

+438
-57
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@
1313

1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
16+
17+
18+
.ci.yml
19+
go.env
20+

Makefile

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# init project path
2+
HOMEDIR := $(shell pwd)
3+
OUTDIR := $(HOMEDIR)/output
4+
5+
# 设置编译时所需要的 go 环境
6+
export GOENV = $(HOMEDIR)/go.env
7+
8+
GO := go
9+
GOMOD := $(GO) mod
10+
GOBUILD := $(GO) build
11+
GOTEST := $(GO) test -race -timeout 30s -gcflags="-N -l"
12+
GOPKGS := $$($(GO) list ./...| grep -vE "vendor")
13+
14+
# test cover files
15+
COVPROF := $(HOMEDIR)/covprof.out # coverage profile
16+
COVFUNC := $(HOMEDIR)/covfunc.txt # coverage profile information for each function
17+
COVHTML := $(HOMEDIR)/covhtml.html # HTML representation of coverage profile
18+
19+
# make, make all
20+
all: prepare compile package
21+
22+
set-env:
23+
$(GO) env
24+
25+
26+
#make prepare, download dependencies
27+
prepare: gomod
28+
29+
gomod: set-env
30+
$(GOMOD) download -x || $(GOMOD) download -x
31+
32+
#make compile
33+
compile: build
34+
35+
build:
36+
$(GOBUILD) -o $(HOMEDIR)/go-hugegraph
37+
38+
# make test, test your code
39+
test: prepare test-case
40+
test-case:
41+
$(GOTEST) -v -cover $(GOPKGS)
42+
43+
# make package
44+
package: package-bin
45+
package-bin:
46+
rm -rf $(OUTDIR)
47+
mkdir -p $(OUTDIR)
48+
mv go-hugegraph $(OUTDIR)/
49+
50+
# make clean
51+
clean:
52+
$(GO) clean
53+
rm -rf $(OUTDIR)
54+
rm -rf $(HOMEDIR)/go-hugegraph
55+
rm -rf $(GOPATH)/pkg/darwin_amd64
56+
57+
# avoid filename conflict and speed up build
58+
.PHONY: all prepare compile test package clean build

ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Global:
2+
version: 2.0
3+
group_email: zhaoliang17@baidu.com # <------ 配置团队邮箱地址,用于接收xx.latest软件版本升级通知邮件
4+
5+
6+
Default:
7+
profile : [build]
8+
9+
Profiles:
10+
- profile:
11+
name : build
12+
mode: AGENT
13+
environment:
14+
image: DECK_CENTOS7U5_K3
15+
resourceType: SMALL
16+
tools:
17+
- go: 1.20.latest
18+
build:
19+
command: make -f Makefile
20+
check:
21+
- reuse: TASK
22+
enable: true
23+
artifacts:
24+
release: true

go.mod

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
module hugegraph
22

3-
go 1.18
3+
go 1.20
4+
5+
require (
6+
github.com/chzyer/readline v1.5.1 // indirect
7+
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd // indirect
8+
github.com/ianlancetaylor/demangle v0.0.0-20211126204342-3ad08eb09c01 // indirect
9+
golang.org/x/sys v0.6.0 // indirect
10+
)

go.sum

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
2+
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ=
3+
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
4+
github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI=
5+
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk=
6+
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
7+
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
8+
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd h1:1FjCyPC+syAzJ5/2S8fqdZK1R22vvA0J7JZKcuOIQ7Y=
9+
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg=
10+
github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
11+
github.com/ianlancetaylor/demangle v0.0.0-20211126204342-3ad08eb09c01 h1:+0qIm4/XbPn2PYkj6QM6CX/FJN5DGvFOaMkSyB1xuh8=
12+
github.com/ianlancetaylor/demangle v0.0.0-20211126204342-3ad08eb09c01/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
13+
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
14+
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
15+
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
16+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

hgapi/api._.go

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hgapi/api.gremlin.get.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"errors"
7-
"fmt"
87
"io"
98
"io/ioutil"
109
"net/http"
@@ -36,10 +35,7 @@ type GremlinGetRequest struct {
3635
}
3736

3837
type GremlinGetRequestReqData struct {
39-
Gremlin string
40-
Bindings string
41-
Language string
42-
Aliases string
38+
Gremlin string `json:"gremlin"`
4339
}
4440

4541
type GremlinGetResponse struct {
@@ -54,13 +50,14 @@ func (r GremlinGetRequest) Do(ctx context.Context, transport Transport) (*Gremli
5450
return nil, errors.New("GremlinGetRequest param error , gremlin is empty")
5551
}
5652

57-
if len(r.GremlinGet.Language) < 1 {
58-
r.GremlinGet.Language = "gremlin-groovy"
59-
}
53+
req, _ := newRequest("GET", "/gremlin", r.Body)
6054

61-
path := fmt.Sprintf("/gremlin?gremlin=%s", url.QueryEscape(r.GremlinGet.Gremlin))
62-
req, _ := newRequest("GET", path, r.Body)
55+
params := url.Values{}
56+
if len(r.GremlinGet.Gremlin) > 0 {
57+
params.Set("gremlin", r.GremlinGet.Gremlin)
58+
}
6359

60+
req.URL.RawQuery = params.Encode()
6461
if ctx != nil {
6562
req = req.WithContext(ctx)
6663
}

hgapi/api.gremlin.post.go

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package hgapi
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"errors"
7+
_ "fmt"
8+
"io"
9+
"io/ioutil"
10+
"net/http"
11+
_ "net/url"
12+
"strings"
13+
)
14+
15+
// ----- API Definition -------------------------------------------------------
16+
17+
// 向HugeGraphServer发送gremlin语句(GET),同步执行
18+
//
19+
// 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
20+
//
21+
func newGremlinPostFunc(t Transport) GremlinPost {
22+
return func(o ...func(*GremlinPostRequest)) (*GremlinPostResponse, error) {
23+
var r = GremlinPostRequest{}
24+
for _, f := range o {
25+
f(&r)
26+
}
27+
return r.Do(r.ctx, t)
28+
}
29+
}
30+
31+
type GremlinPost func(o ...func(*GremlinPostRequest)) (*GremlinPostResponse, error)
32+
33+
type GremlinPostRequest struct {
34+
ctx context.Context
35+
Body io.ReadCloser `json:"-"`
36+
GremlinPost *GremlinPostRequestReqData
37+
}
38+
39+
type GremlinPostRequestReqData struct {
40+
Gremlin string `json:"gremlin"`
41+
Bindings map[string]string `json:"bindings,omitempty"`
42+
Language string `json:"language"`
43+
Aliases struct {
44+
Graph string `json:"graph"`
45+
G string `json:"g"`
46+
} `json:"aliases"`
47+
}
48+
49+
type GremlinPostResponse struct {
50+
StatusCode int `json:"-"`
51+
Header http.Header `json:"-"`
52+
Body io.ReadCloser `json:"-"`
53+
Data *GremlinPostResponseData `json:"data"`
54+
}
55+
56+
type GremlinPostResponseData struct {
57+
RequestID string `json:"requestId,omitempty"`
58+
Status struct {
59+
Message string `json:"message"`
60+
Code int `json:"code"`
61+
Attributes struct {
62+
} `json:"attributes"`
63+
} `json:"status"`
64+
Result struct {
65+
Data interface{} `json:"data"`
66+
Meta struct {
67+
} `json:"meta"`
68+
} `json:"result,omitempty"`
69+
Exception string `json:"exception,omitempty"`
70+
Message string `json:"message,omitempty"`
71+
Cause string `json:"cause,omitempty"`
72+
Trace []string `json:"trace,omitempty"`
73+
}
74+
75+
func (r GremlinPostRequest) Do(ctx context.Context, transport Transport) (*GremlinPostResponse, error) {
76+
77+
if len(r.GremlinPost.Gremlin) < 1 {
78+
return nil, errors.New("GremlinPostRequest param error , gremlin is empty")
79+
}
80+
81+
if len(r.GremlinPost.Language) < 1 {
82+
r.GremlinPost.Language = "gremlin-groovy"
83+
}
84+
85+
// 重新修改参数
86+
r.GremlinPost.Aliases = struct {
87+
Graph string `json:"graph"`
88+
G string `json:"g"`
89+
}(struct {
90+
Graph string
91+
G string
92+
}{
93+
Graph: "${GRAPH_SPACE_NAME}-${GRAPH_NAME}",
94+
G: "__g_${GRAPH_SPACE_NAME}-${GRAPH_NAME}",
95+
})
96+
97+
byteBody, err := json.Marshal(&r.GremlinPost) // 序列化
98+
99+
if err != nil {
100+
return nil, err
101+
}
102+
103+
reader := strings.NewReader(string(byteBody)) // 转化为reader
104+
105+
req, _ := newRequest("POST", "/gremlin", reader)
106+
107+
if ctx != nil {
108+
req = req.WithContext(ctx)
109+
}
110+
111+
res, err := transport.Perform(req)
112+
if err != nil {
113+
return nil, err
114+
}
115+
116+
gremlinPostResp := &GremlinPostResponse{}
117+
bytes, err := ioutil.ReadAll(res.Body)
118+
if err != nil {
119+
return nil, err
120+
}
121+
122+
respData := &GremlinPostResponseData{}
123+
err = json.Unmarshal(bytes, respData)
124+
if err != nil {
125+
return nil, err
126+
}
127+
gremlinPostResp.StatusCode = res.StatusCode
128+
gremlinPostResp.Header = res.Header
129+
gremlinPostResp.Body = res.Body
130+
gremlinPostResp.Data = respData
131+
return gremlinPostResp, nil
132+
}
133+
134+
func (g *GremlinPost) WithGremlinPostData(gremlin GremlinPostRequestReqData) func(*GremlinPostRequest) {
135+
return func(r *GremlinPostRequest) {
136+
r.GremlinPost = &gremlin
137+
}
138+
}

hgapi/api.property_keys.create.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package hgapi
33
import (
44
"context"
55
"encoding/json"
6+
"hugegraph/internal/model"
67
"io"
78
"io/ioutil"
89
"net/http"
@@ -84,7 +85,7 @@ func (r PropertyKeysCreateRequest) Do(ctx context.Context, transport Transport)
8485
}
8586
byteBody, _ := json.Marshal(&r) // 序列化
8687
reader := strings.NewReader(string(byteBody)) // 转化为reader
87-
req, _ := newRequest("POST", "/graphs/${GRAPH_NAME}/schema/propertykeys", reader)
88+
req, _ := newRequest("POST", model.UrlPrefix+"/graphs/${GRAPH_NAME}/schema/propertykeys", reader)
8889

8990
if ctx != nil {
9091
req = req.WithContext(ctx)

hgapi/api.property_keys.delete_by_name.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"hugegraph/internal/model"
89
"io"
910
"io/ioutil"
1011
"net/http"
@@ -46,7 +47,7 @@ func (r PropertyKeysDeleteByNameRequest) Do(ctx context.Context, transport Trans
4647
return nil, errors.New("PropertyKeysDeleteByNameRequest Param error, name is not empty")
4748
}
4849

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

5152
if ctx != nil {
5253
req = req.WithContext(ctx)

0 commit comments

Comments
 (0)