You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hugegraph.apache.org by "izliang (via GitHub)" <gi...@apache.org> on 2023/08/28 11:40:21 UTC
[GitHub] [incubator-hugegraph-toolchain] izliang opened a new pull request, #514: Feature go client : #512
izliang opened a new pull request, #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514
## Purpose of the PR
close #512
## Main Changes
Add Hugegraph-client for golang
Support REST API By This feature
## Verifying these changes
<!-- Please pick the proper options below -->
- [ ] Trivial rework / code cleanup without any test coverage. (No Need)
- [x] Already covered by existing tests, such as *(make test)*.
- [ ] Need tests and can be verified as follows:
- xxx
## Does this PR potentially affect the following parts?
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [x] Nope
- [ ] Dependencies (add/update license info) <!-- Don't forget to add/update the info in "LICENSE" & "NOTICE" files (both in root & dist module) -->
- [ ] Modify configurations
- [ ] The public API
- [ ] Other affects (typed here)
## Documentation Status
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [x] `Doc - TODO` <!-- Your PR changes impact docs and you will update later -->
- [ ] `Doc - Done` <!-- Related docs have been already added or updated -->
- [ ] `Doc - No Need` <!-- Your PR changes don't impact/need docs -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
[GitHub] [incubator-hugegraph-toolchain] izliang commented on a diff in pull request #514: feature : add go client
Posted by "izliang (via GitHub)" <gi...@apache.org>.
izliang commented on code in PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#discussion_r1328052202
##########
hugegraph-client-go/hgapi/hgapi.go:
##########
@@ -0,0 +1,45 @@
+package hgapi
+
+import (
+ "net/http"
+ "strconv"
+ "time"
+
+ "hugegraph.apache.org/client-go/internal/version"
+)
+
+// VERSION returns the package version as a string.
+//
+const VERSION = version.Client
+
+// Transport defines the interface for an API client.
+//
+type Transport interface {
+ Perform(*http.Request) (*http.Response, error)
+}
+
+// BoolPtr returns a pointer to v.
+//
+// It is used as a convenience function for converting a bool value
+// into a pointer when passing the value to a function or struct field
+// which expects a pointer.
+//
+func BoolPtr(v bool) *bool { return &v }
+
+// IntPtr returns a pointer to v.
+//
+// It is used as a convenience function for converting an int value
+// into a pointer when passing the value to a function or struct field
+// which expects a pointer.
+//
+func IntPtr(v int) *int { return &v }
Review Comment:
I will modify it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
[GitHub] [incubator-hugegraph-toolchain] izliang commented on a diff in pull request #514: feature : add go client
Posted by "izliang (via GitHub)" <gi...@apache.org>.
izliang commented on code in PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#discussion_r1328052179
##########
hugegraph-client-go/Makefile:
##########
@@ -0,0 +1,58 @@
+# init project path
+HOMEDIR := $(shell pwd)
+OUTDIR := $(HOMEDIR)/output
+
+# 设置编译时所需要的 go 环境
+export GOENV = $(HOMEDIR)/go.env
+
+GO := go
+GOMOD := $(GO) mod
+GOBUILD := $(GO) build
+GOTEST := $(GO) test -race -timeout 30s -gcflags="-N -l"
+GOPKGS := $$($(GO) list ./...| grep -vE "vendor")
+
+# test cover files
+COVPROF := $(HOMEDIR)/covprof.out # coverage profile
+COVFUNC := $(HOMEDIR)/covfunc.txt # coverage profile information for each function
+COVHTML := $(HOMEDIR)/covhtml.html # HTML representation of coverage profile
+
+# make, make all
+all: prepare compile package
+
+set-env:
+ $(GO) env
+
+
+#make prepare, download dependencies
+prepare: gomod
+
+gomod: set-env
+ $(GOMOD) download -x || $(GOMOD) download -x
+
+#make compile
+compile: build
+
+build:
+ $(GOBUILD) -o $(HOMEDIR)/go-hugegraph
Review Comment:
I will modify it
##########
hugegraph-client-go/Makefile:
##########
@@ -0,0 +1,58 @@
+# init project path
+HOMEDIR := $(shell pwd)
+OUTDIR := $(HOMEDIR)/output
+
+# 设置编译时所需要的 go 环境
+export GOENV = $(HOMEDIR)/go.env
+
+GO := go
Review Comment:
I will modify it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feature(client): support go client for hugegraph [incubator-hugegraph-toolchain]
Posted by "qwtsc (via GitHub)" <gi...@apache.org>.
qwtsc commented on PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#issuecomment-1840424886
I think you can try something like this [openapi generator](https://github.com/OpenAPITools/openapi-generator). Other parts LGTM.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feature(client): support go client for hugegraph [incubator-hugegraph-toolchain]
Posted by "z7658329 (via GitHub)" <gi...@apache.org>.
z7658329 commented on code in PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#discussion_r1382747926
##########
hugegraph-client-go/api/api.response.go:
##########
Review Comment:
> Normally, in Go language, underline is used as the file separator. Here, because the API is a tree structure, English commas are used to distinguish between trees, and then underline is used for segmentation. For example: api.veretx.create.go and api.vertex.get_ by_id.go . The use of English commas and underscores is more conducive to presentation and layering.
@izliang @hankwenyx
should we follow the example of other graph communities? like nebula community go's sdk, seems does not use this naming style:

how about the following style:
- main.go
- api/
- user/
- user.go
- product/
- product.go
- order/
- order.go
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feature(client): support go client for hugegraph [incubator-hugegraph-toolchain]
Posted by "izliang (via GitHub)" <gi...@apache.org>.
izliang commented on code in PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#discussion_r1368310622
##########
hugegraph-client-go/api/api.response.go:
##########
Review Comment:
Normally, in Go language, underline is used as the file separator. Here, because the API is a tree structure, English commas are used to distinguish between trees, and then underline is used for segmentation. For example: api.veretx.create.go and api.vertex.get_ by_id.go . The use of English commas and underscores is more conducive to presentation and layering.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feature(client): support go client for hugegraph [incubator-hugegraph-toolchain]
Posted by "zyxxoo (via GitHub)" <gi...@apache.org>.
zyxxoo commented on PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#issuecomment-1793952907
> At present, it is necessary to explore implementation solutions for the design of file directories and responsibilities for various APIs. There are currently several design options available:
>
> 1. In the form of one API per file, this solution references the design of ElasticSerach. [Code library address](https://github.com/elastic/go-elasticsearch/tree/main/esapi)
> 2. Using all one file and API formats, this solution references the design of Prometheus. [Code library address](https://github.com/prometheus/client_golang/blob/main/api/prometheus/v1/api.go)
> 3. By aggregating some APIs into a single file, this solution refers to the design of Influxdb. [Code library address](https://github.com/influxdata/influxdb-client-go/blob/master/api/query.go)
>
> @zyxxoo @hankwenyx @javeme @coderzc @Radeity could choose one
Good idea, Maybe I choose 3 =.=, this style like with java style
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feature(client): support go client for hugegraph [incubator-hugegraph-toolchain]
Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin commented on PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#issuecomment-1822251319
need handle some CI problems:
https://github.com/apache/incubator-hugegraph-toolchain/actions/runs/6951881673/job/18916919111?pr=514
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
[GitHub] [incubator-hugegraph-toolchain] zyxxoo commented on a diff in pull request #514: feature : add go client
Posted by "zyxxoo (via GitHub)" <gi...@apache.org>.
zyxxoo commented on code in PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#discussion_r1309518803
##########
hugegraph-client-go/Makefile:
##########
@@ -0,0 +1,58 @@
+# init project path
+HOMEDIR := $(shell pwd)
+OUTDIR := $(HOMEDIR)/output
+
+# 设置编译时所需要的 go 环境
+export GOENV = $(HOMEDIR)/go.env
+
+GO := go
+GOMOD := $(GO) mod
+GOBUILD := $(GO) build
+GOTEST := $(GO) test -race -timeout 30s -gcflags="-N -l"
+GOPKGS := $$($(GO) list ./...| grep -vE "vendor")
+
+# test cover files
+COVPROF := $(HOMEDIR)/covprof.out # coverage profile
+COVFUNC := $(HOMEDIR)/covfunc.txt # coverage profile information for each function
+COVHTML := $(HOMEDIR)/covhtml.html # HTML representation of coverage profile
+
+# make, make all
+all: prepare compile package
+
+set-env:
+ $(GO) env
+
+
+#make prepare, download dependencies
+prepare: gomod
+
+gomod: set-env
+ $(GOMOD) download -x || $(GOMOD) download -x
+
+#make compile
+compile: build
+
+build:
+ $(GOBUILD) -o $(HOMEDIR)/go-hugegraph
Review Comment:
${HOMEDIR}/bin
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feature(client): support go client for hugegraph [incubator-hugegraph-toolchain]
Posted by "javeme (via GitHub)" <gi...@apache.org>.
javeme commented on code in PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#discussion_r1366454830
##########
.github/workflows/client-go-ci.yml:
##########
@@ -0,0 +1,66 @@
+name: "hugegraph-client-go-ci"
+
+on:
+ push:
+ branches:
+ - master
+ - feature-go-client
+ - /^release-.*$/
+ - /^feature-.*$/
+ paths:
+ - hugegraph-client-go/**
+ - hugegraph-dist/**
+ - .github/workflows/**
+ - pom.xml
+ pull_request:
+ paths:
+ - hugegraph-client-go/**
+ - hugegraph-dist/**
+ - .github/workflows/**
+ - pom.xml
+
+jobs:
+ client-go-ci:
+ runs-on: ubuntu-20.04
+ env:
+ TRAVIS_DIR: hugegraph-client/assembly/travis
+ COMMIT_ID: be6ee386b9939dc6bd6fcbdf2274b8acc3a0a314
+ strategy:
+ fail-fast: false
+ matrix:
+ JAVA_VERSION: ['8']
+ steps:
+ - name: Install JDK 8
+ uses: actions/setup-java@v3
+ with:
+ java-version: ${{ matrix.JAVA_VERSION }}
+ distribution: 'zulu'
+
+ - name: Cache Maven packages
+ uses: actions/cache@v3
+ with:
+ path: ~/.m2
+ key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
+ restore-keys: ${{ runner.os }}-m2
+
+ - name: Checkout
+ uses: actions/checkout@v3
+ with:
+ fetch-depth: 2
+
+ - name: Prepare env and service
+ run: |
+ $TRAVIS_DIR/install-hugegraph-from-source.sh $COMMIT_ID
+
+ - name: Init Go env
+ uses: actions/setup-go@v2.1.3
+ with: { go-version: '1.x' }
+
+ - name: Go test
+ run: |
+ go version
+ sudo swapoff -a
+ sudo sysctl -w vm.swappiness=1
+ sudo sysctl -w fs.file-max=262144
+ sudo sysctl -w vm.max_map_count=262144
+ cd hugegraph-client-go && make test
Review Comment:
expect a blank line here
##########
hugegraph-client-go/internal/model/model.go:
##########
@@ -0,0 +1,21 @@
+/*
+ * 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 model
+
+// UrlPrefix 用于增加对商业版的支持
Review Comment:
ditto
##########
hugegraph-client-go/README.md:
##########
@@ -0,0 +1,85 @@
+# go-hugegraph
+
+#### 介绍
+
+基于 Go 语言的 hugegraph client SDK 工具
+
+#### 软件架构
+
+软件架构说明
+
+#### 安装教程
+
+```shell
+go get github.com/go-hugegraph
+```
+
+#### 实现 API
+
+| API | 说明 |
+|---------|-------------|
+| schema | 获取模型 schema |
+| version | 获取版本信息 |
+
+#### 使用说明
+
+##### 1.初始化客户端
+
+```go
+package main
+
+import "hugegraph.apache.org/client-go"
+import "hugegraph.apache.org/client-go/hgtransport"
+
+func main() {
+
+ clinet,err := hugegraph.NewClient(hugegraph.Config{
+ Host: "127.0.0.1",
+ Port: 8888,
+ Graph: "hugegraph",
+ Logger: &hgtransport.ColorLogger{
+ Output: os.Stdout,
+ EnableRequestBody: true,
+ EnableResponseBody: true,
+ },
+ })
+
+ if err != nil {
+ log.Fatalf("Error creating the client: %s\n", err)
+ }
+}
+```
+
+##### 2.获取 hugegraph 版本
+
+- 1.使用 SDK 获取版本信息
+
+```go
+func getVersion() {
+
+ client := initClient()
+
+ res, err := client.Version()
+ if err != nil {
+ log.Fatalf("Error getting the response: %s\n", err)
Review Comment:
note indentation
##########
hugegraph-client-go/README.md:
##########
@@ -0,0 +1,85 @@
+# go-hugegraph
+
+#### 介绍
+
+基于 Go 语言的 hugegraph client SDK 工具
+
+#### 软件架构
+
+软件架构说明
+
+#### 安装教程
+
+```shell
+go get github.com/go-hugegraph
+```
+
+#### 实现 API
+
+| API | 说明 |
+|---------|-------------|
+| schema | 获取模型 schema |
+| version | 获取版本信息 |
+
+#### 使用说明
+
+##### 1.初始化客户端
+
+```go
+package main
+
+import "hugegraph.apache.org/client-go"
+import "hugegraph.apache.org/client-go/hgtransport"
+
+func main() {
+
+ clinet,err := hugegraph.NewClient(hugegraph.Config{
+ Host: "127.0.0.1",
+ Port: 8888,
+ Graph: "hugegraph",
+ Logger: &hgtransport.ColorLogger{
+ Output: os.Stdout,
+ EnableRequestBody: true,
+ EnableResponseBody: true,
+ },
+ })
+
+ if err != nil {
+ log.Fatalf("Error creating the client: %s\n", err)
+ }
+}
+```
+
+##### 2.获取 hugegraph 版本
+
+- 1.使用 SDK 获取版本信息
+
+```go
+func getVersion() {
+
+ client := initClient()
+
+ res, err := client.Version()
+ if err != nil {
+ log.Fatalf("Error getting the response: %s\n", err)
+ }
+ defer res.Body.Close()
+
+ fmt.Println(res.Versions)
+
+ fmt.Println(res.Versions.Version)
+}
+```
+
+- 2.结果集响应体
+
+```go
+type VersionResponse struct {
+ Versions struct {
+ Version string `json:"version"`
+ Core string `json:"core"`
+ Gremlin string `json:"gremlin"`
+ API string `json:"api"`
+ } `json:"versions"`
+}
+```
Review Comment:
能否简略的说明下版本信息的内容?比如`返回结果包括了各个子模块的版本号`
##########
hugegraph-client-go/README.md:
##########
@@ -0,0 +1,85 @@
+# go-hugegraph
+
+#### 介绍
+
+基于 Go 语言的 hugegraph client SDK 工具
+
+#### 软件架构
+
+软件架构说明
+
+#### 安装教程
+
+```shell
+go get github.com/go-hugegraph
+```
+
+#### 实现 API
+
+| API | 说明 |
+|---------|-------------|
+| schema | 获取模型 schema |
+| version | 获取版本信息 |
+
+#### 使用说明
+
+##### 1.初始化客户端
+
+```go
+package main
+
+import "hugegraph.apache.org/client-go"
+import "hugegraph.apache.org/client-go/hgtransport"
+
+func main() {
+
+ clinet,err := hugegraph.NewClient(hugegraph.Config{
+ Host: "127.0.0.1",
+ Port: 8888,
+ Graph: "hugegraph",
+ Logger: &hgtransport.ColorLogger{
+ Output: os.Stdout,
+ EnableRequestBody: true,
+ EnableResponseBody: true,
+ },
+ })
+
+ if err != nil {
+ log.Fatalf("Error creating the client: %s\n", err)
+ }
+}
+```
+
+##### 2.获取 hugegraph 版本
+
+- 1.使用 SDK 获取版本信息
+
+```go
+func getVersion() {
+
+ client := initClient()
+
+ res, err := client.Version()
+ if err != nil {
+ log.Fatalf("Error getting the response: %s\n", err)
+ }
+ defer res.Body.Close()
+
+ fmt.Println(res.Versions)
+
+ fmt.Println(res.Versions.Version)
+}
+```
+
+- 2.结果集响应体
+
+```go
+type VersionResponse struct {
+ Versions struct {
+ Version string `json:"version"`
+ Core string `json:"core"`
+ Gremlin string `json:"gremlin"`
+ API string `json:"api"`
+ } `json:"versions"`
+}
+```
Review Comment:
能否简略的说明下版本信息的内容?比如`返回结果包括了各个子模块的版本号`
##########
hugegraph-client-go/hugegraph.go:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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 hugegraph
+
+import (
+ "errors"
+ "fmt"
+ "net"
+ "net/http"
+ "net/url"
+ "os"
+
+ v1 "hugegraph.apache.org/client-go/api/v1"
+ "hugegraph.apache.org/client-go/hgtransport"
+)
+
+// ClientTypeEnum 客户端类型枚举
Review Comment:
ditto
##########
pom.xml:
##########
@@ -28,7 +28,8 @@
<name>${project.artifactId}</name>
<url>https://github.com/apache/incubator-hugegraph-toolchain</url>
<description>
- hugegraph-toolchain is the integration project of a series of utilities for HugeGraph, it includes 4 main modules (loader/hubble/tools/client)
+ hugegraph-toolchain is the integration project of a series of utilities for HugeGraph, it
+ includes 4 main modules (loader/hubble/tools/client)
Review Comment:
seems don't need to wrap line
##########
hugegraph-client-go/README.md:
##########
@@ -0,0 +1,85 @@
+# go-hugegraph
+
+#### 介绍
+
+基于 Go 语言的 hugegraph client SDK 工具
+
+#### 软件架构
+
+软件架构说明
+
+#### 安装教程
+
+```shell
+go get github.com/go-hugegraph
+```
+
+#### 实现 API
+
+| API | 说明 |
+|---------|-------------|
+| schema | 获取模型 schema |
+| version | 获取版本信息 |
+
+#### 使用说明
+
+##### 1.初始化客户端
+
+```go
+package main
+
+import "hugegraph.apache.org/client-go"
+import "hugegraph.apache.org/client-go/hgtransport"
+
+func main() {
+
+ clinet,err := hugegraph.NewClient(hugegraph.Config{
+ Host: "127.0.0.1",
Review Comment:
can we replace all the TAB to spaces?
##########
hugegraph-client-go/README.md:
##########
@@ -0,0 +1,85 @@
+# go-hugegraph
+
+#### 介绍
+
+基于 Go 语言的 hugegraph client SDK 工具
+
+#### 软件架构
+
+软件架构说明
+
+#### 安装教程
+
+```shell
+go get github.com/go-hugegraph
+```
+
+#### 实现 API
+
+| API | 说明 |
+|---------|-------------|
+| schema | 获取模型 schema |
+| version | 获取版本信息 |
+
+#### 使用说明
+
+##### 1.初始化客户端
+
+```go
+package main
+
+import "hugegraph.apache.org/client-go"
+import "hugegraph.apache.org/client-go/hgtransport"
+
+func main() {
+
Review Comment:
unused blank line?
##########
hugegraph-client-go/api/v1/api.version.go:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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"
+ "io"
+ "io/ioutil"
+ "net/http"
+
+ "hugegraph.apache.org/client-go/api"
+)
+
+// ----- API Definition -------------------------------------------------------
+
+// 查看HugeGraph的版本信息
Review Comment:
ditto
##########
hugegraph-client-go/README.md:
##########
@@ -0,0 +1,85 @@
+# go-hugegraph
+
+#### 介绍
+
+基于 Go 语言的 hugegraph client SDK 工具
+
+#### 软件架构
+
+软件架构说明
+
+#### 安装教程
+
+```shell
+go get github.com/go-hugegraph
+```
+
+#### 实现 API
+
+| API | 说明 |
+|---------|-------------|
+| schema | 获取模型 schema |
+| version | 获取版本信息 |
+
+#### 使用说明
+
+##### 1.初始化客户端
+
+```go
+package main
+
+import "hugegraph.apache.org/client-go"
+import "hugegraph.apache.org/client-go/hgtransport"
+
+func main() {
+
+ clinet,err := hugegraph.NewClient(hugegraph.Config{
+ Host: "127.0.0.1",
+ Port: 8888,
+ Graph: "hugegraph",
+ Logger: &hgtransport.ColorLogger{
+ Output: os.Stdout,
+ EnableRequestBody: true,
+ EnableResponseBody: true,
+ },
+ })
+
+ if err != nil {
+ log.Fatalf("Error creating the client: %s\n", err)
+ }
+}
+```
+
+##### 2.获取 hugegraph 版本
+
+- 1.使用 SDK 获取版本信息
+
+```go
+func getVersion() {
+
+ client := initClient()
+
+ res, err := client.Version()
+ if err != nil {
+ log.Fatalf("Error getting the response: %s\n", err)
+ }
+ defer res.Body.Close()
+
+ fmt.Println(res.Versions)
+
+ fmt.Println(res.Versions.Version)
+}
+```
+
+- 2.结果集响应体
Review Comment:
`返回值的结构`更好理解一些
##########
hugegraph-client-go/README.md:
##########
@@ -0,0 +1,85 @@
+# go-hugegraph
+
+#### 介绍
+
+基于 Go 语言的 hugegraph client SDK 工具
+
+#### 软件架构
+
+软件架构说明
+
+#### 安装教程
+
+```shell
+go get github.com/go-hugegraph
+```
+
+#### 实现 API
+
+| API | 说明 |
+|---------|-------------|
+| schema | 获取模型 schema |
+| version | 获取版本信息 |
+
+#### 使用说明
+
+##### 1.初始化客户端
+
+```go
+package main
+
+import "hugegraph.apache.org/client-go"
+import "hugegraph.apache.org/client-go/hgtransport"
+
+func main() {
+
+ clinet,err := hugegraph.NewClient(hugegraph.Config{
+ Host: "127.0.0.1",
+ Port: 8888,
+ Graph: "hugegraph",
+ Logger: &hgtransport.ColorLogger{
+ Output: os.Stdout,
+ EnableRequestBody: true,
+ EnableResponseBody: true,
+ },
+ })
+
+ if err != nil {
+ log.Fatalf("Error creating the client: %s\n", err)
+ }
+}
+```
+
+##### 2.获取 hugegraph 版本
+
+- 1.使用 SDK 获取版本信息
+
+```go
+func getVersion() {
+
+ client := initClient()
+
+ res, err := client.Version()
+ if err != nil {
+ log.Fatalf("Error getting the response: %s\n", err)
+ }
+ defer res.Body.Close()
+
+ fmt.Println(res.Versions)
+
+ fmt.Println(res.Versions.Version)
+}
+```
+
+- 2.结果集响应体
Review Comment:
`返回值的结构`更好理解一些
##########
hugegraph-client-go/Makefile:
##########
@@ -0,0 +1,75 @@
+#
+# 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.
+#
+
+# init project path
+HOMEDIR := $(shell pwd)
+OUTDIR := $(HOMEDIR)/output
+
+# 设置编译时所需要的 go 环境
Review Comment:
can we translate it to english?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feature(client): support go client for hugegraph [incubator-hugegraph-toolchain]
Posted by "javeme (via GitHub)" <gi...@apache.org>.
javeme commented on PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#issuecomment-1806677772
> At present, it is necessary to explore implementation solutions for the design of file directories and responsibilities for various APIs. There are currently several design options available:
>
> 1. In the form of one API per file, this solution references the design of ElasticSerach. [Code library address](https://github.com/elastic/go-elasticsearch/tree/main/esapi)
> 2. Using all one file and API formats, this solution references the design of Prometheus. [Code library address](https://github.com/prometheus/client_golang/blob/main/api/prometheus/v1/api.go)
> 3. By aggregating some APIs into a single file, this solution refers to the design of Influxdb. [Code library address](https://github.com/influxdata/influxdb-client-go/blob/master/api/query.go)
>
> @zyxxoo @hankwenyx @javeme @coderzc @Radeity could choose one
I am not familiar with the Go language, you can refer to zyxxoo and coderzc's suggestions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
[GitHub] [incubator-hugegraph-toolchain] zyxxoo commented on a diff in pull request #514: feature : add go client
Posted by "zyxxoo (via GitHub)" <gi...@apache.org>.
zyxxoo commented on code in PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#discussion_r1309521105
##########
hugegraph-client-go/Makefile:
##########
@@ -0,0 +1,58 @@
+# init project path
+HOMEDIR := $(shell pwd)
+OUTDIR := $(HOMEDIR)/output
+
+# 设置编译时所需要的 go 环境
+export GOENV = $(HOMEDIR)/go.env
+
+GO := go
+GOMOD := $(GO) mod
+GOBUILD := $(GO) build
+GOTEST := $(GO) test -race -timeout 30s -gcflags="-N -l"
+GOPKGS := $$($(GO) list ./...| grep -vE "vendor")
+
+# test cover files
+COVPROF := $(HOMEDIR)/covprof.out # coverage profile
+COVFUNC := $(HOMEDIR)/covfunc.txt # coverage profile information for each function
+COVHTML := $(HOMEDIR)/covhtml.html # HTML representation of coverage profile
+
+# make, make all
+all: prepare compile package
+
+set-env:
+ $(GO) env
+
+
+#make prepare, download dependencies
+prepare: gomod
+
+gomod: set-env
+ $(GOMOD) download -x || $(GOMOD) download -x
+
+#make compile
+compile: build
+
+build:
+ $(GOBUILD) -o $(HOMEDIR)/go-hugegraph
Review Comment:
GO111MODULE=on
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feature(client): support go client for hugegraph [incubator-hugegraph-toolchain]
Posted by "coderzc (via GitHub)" <gi...@apache.org>.
coderzc commented on PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#issuecomment-1805461183
> At present, it is necessary to explore implementation solutions for the design of file directories and responsibilities for various APIs. There are currently several design options available:
>
> 1. In the form of one API per file, this solution references the design of ElasticSerach. [Code library address](https://github.com/elastic/go-elasticsearch/tree/main/esapi)
> 2. Using all one file and API formats, this solution references the design of Prometheus. [Code library address](https://github.com/prometheus/client_golang/blob/main/api/prometheus/v1/api.go)
> 3. By aggregating some APIs into a single file, this solution refers to the design of Influxdb. [Code library address](https://github.com/influxdata/influxdb-client-go/blob/master/api/query.go)
>
> @zyxxoo @hankwenyx @javeme @coderzc @Radeity could choose one
I also think 3nd is better.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feature(client): support go client for hugegraph [incubator-hugegraph-toolchain]
Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin merged PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feature(client): support go client for hugegraph [incubator-hugegraph-toolchain]
Posted by "izliang (via GitHub)" <gi...@apache.org>.
izliang commented on PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#issuecomment-1792069724
At present, it is necessary to explore implementation solutions for the design of file directories and responsibilities for various APIs. There are currently several design options available:
1. In the form of one API per file, this solution references the design of ElasticSerach. [Code library address:](https://github.com/elastic/go-elasticsearch/tree/main/esapi)
2. Using all one file and API formats, this solution references the design of Prometheus. [Code library address:](https://github.com/prometheus/client_golang/blob/main/api/prometheus/v1/api.go)
3. By aggregating some APIs into a single file, this solution refers to the design of Influxdb. [Code library address:](https://github.com/influxdata/influxdb-client-go/blob/master/api/query.go)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
[GitHub] [incubator-hugegraph-toolchain] zyxxoo commented on a diff in pull request #514: feature : add go client
Posted by "zyxxoo (via GitHub)" <gi...@apache.org>.
zyxxoo commented on code in PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#discussion_r1309528959
##########
hugegraph-client-go/Makefile:
##########
@@ -0,0 +1,58 @@
+# init project path
+HOMEDIR := $(shell pwd)
+OUTDIR := $(HOMEDIR)/output
+
+# 设置编译时所需要的 go 环境
+export GOENV = $(HOMEDIR)/go.env
+
+GO := go
Review Comment:
GO := GO111MODULE=on go
##########
hugegraph-client-go/Makefile:
##########
@@ -0,0 +1,58 @@
+# init project path
+HOMEDIR := $(shell pwd)
+OUTDIR := $(HOMEDIR)/output
+
+# 设置编译时所需要的 go 环境
+export GOENV = $(HOMEDIR)/go.env
+
+GO := go
+GOMOD := $(GO) mod
+GOBUILD := $(GO) build
+GOTEST := $(GO) test -race -timeout 30s -gcflags="-N -l"
+GOPKGS := $$($(GO) list ./...| grep -vE "vendor")
+
+# test cover files
+COVPROF := $(HOMEDIR)/covprof.out # coverage profile
+COVFUNC := $(HOMEDIR)/covfunc.txt # coverage profile information for each function
+COVHTML := $(HOMEDIR)/covhtml.html # HTML representation of coverage profile
+
+# make, make all
+all: prepare compile package
+
+set-env:
Review Comment:
print-env?
##########
hugegraph-client-go/Makefile:
##########
@@ -0,0 +1,58 @@
+# init project path
+HOMEDIR := $(shell pwd)
+OUTDIR := $(HOMEDIR)/output
+
+# 设置编译时所需要的 go 环境
+export GOENV = $(HOMEDIR)/go.env
+
+GO := go
+GOMOD := $(GO) mod
+GOBUILD := $(GO) build
+GOTEST := $(GO) test -race -timeout 30s -gcflags="-N -l"
+GOPKGS := $$($(GO) list ./...| grep -vE "vendor")
+
+# test cover files
+COVPROF := $(HOMEDIR)/covprof.out # coverage profile
+COVFUNC := $(HOMEDIR)/covfunc.txt # coverage profile information for each function
+COVHTML := $(HOMEDIR)/covhtml.html # HTML representation of coverage profile
+
+# make, make all
+all: prepare compile package
+
+set-env:
+ $(GO) env
+
+
+#make prepare, download dependencies
+prepare: gomod
+
+gomod: set-env
Review Comment:
gomod maybe rename tidy or download?
##########
hugegraph-client-go/hgtransport/hgtransport.go:
##########
@@ -0,0 +1,246 @@
+package hgtransport
+
+import (
+ "bytes"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "net/url"
+ "regexp"
+ "runtime"
+ "strings"
+ "time"
+
+ "hugegraph.apache.org/client-go/internal/version"
+)
+
+// Version returns the package version as a string.
+//
+const Version = version.Client
+
+var (
+ userAgent string
+ reGoVersion = regexp.MustCompile(`go(\d+\.\d+\..+)`)
+)
+
+func init() {
+ userAgent = initUserAgent()
+}
+
+// Interface defines the interface for HTTP client.
+//
+type Interface interface {
+ Perform(*http.Request) (*http.Response, error)
+}
+
+// Config represents the configuration of HTTP client.
+//
+type Config struct {
+ URL *url.URL
+ Username string
+ Password string
+ GraphSpace string
+ Graph string
+
+ Transport http.RoundTripper
+ Logger Logger
+}
+
+// Client represents the HTTP client.
+//
+type Client struct {
+ url *url.URL
+ username string
+ password string
+ graphspaces string
+ graph string
+
+ transport http.RoundTripper
+ logger Logger
+}
+
+// New creates new HTTP client.
+//
+// http.DefaultTransport will be used if no transport is passed in the configuration.
+//
+func New(cfg Config) *Client {
+ if cfg.Transport == nil {
+ cfg.Transport = http.DefaultTransport
+ }
+
+ return &Client{
+ url: cfg.URL,
+ username: cfg.Username,
+ password: cfg.Password,
+ graphspaces: cfg.GraphSpace,
+ graph: cfg.Graph,
+ transport: cfg.Transport,
+ logger: cfg.Logger,
+ }
+}
+
+// Perform executes the request and returns a response or error.
+//
+func (c *Client) Perform(req *http.Request) (*http.Response, error) {
+
+ u := c.url
+ c.setURL(u, req)
+ c.setUserAgent(req)
+ c.setHost(req)
+ c.setContentTypeJSON(req)
+ c.setGraph(req)
+ c.setGraphSpace(req)
+ c.setBodyGraphInfo(req)
+
+ if _, ok := req.Header["Authorization"]; !ok {
+ c.setBasicAuth(u, req)
+ }
+
+ fmt.Println(req.Header)
+ var dupReqBody *bytes.Buffer
+ if c.logger != nil && c.logger.RequestBodyEnabled() {
+ if req.Body != nil && req.Body != http.NoBody {
+ dupReqBody = bytes.NewBuffer(make([]byte, 0, int(req.ContentLength)))
+ dupReqBody.ReadFrom(req.Body)
+ req.Body = ioutil.NopCloser(bytes.NewBuffer(dupReqBody.Bytes()))
+ }
+ }
+ start := time.Now().UTC()
+ res, err := c.transport.RoundTrip(req)
+ dur := time.Since(start)
+ if c.logger != nil {
Review Comment:
reduce if nesting
##########
hugegraph-client-go/hgapi/hgapi.go:
##########
@@ -0,0 +1,45 @@
+package hgapi
+
+import (
+ "net/http"
+ "strconv"
+ "time"
+
+ "hugegraph.apache.org/client-go/internal/version"
+)
+
+// VERSION returns the package version as a string.
+//
+const VERSION = version.Client
+
+// Transport defines the interface for an API client.
+//
+type Transport interface {
+ Perform(*http.Request) (*http.Response, error)
+}
+
+// BoolPtr returns a pointer to v.
+//
+// It is used as a convenience function for converting a bool value
+// into a pointer when passing the value to a function or struct field
+// which expects a pointer.
+//
+func BoolPtr(v bool) *bool { return &v }
+
+// IntPtr returns a pointer to v.
+//
+// It is used as a convenience function for converting an int value
+// into a pointer when passing the value to a function or struct field
+// which expects a pointer.
+//
+func IntPtr(v int) *int { return &v }
Review Comment:
maybe boolPtr and IntPtr are unnecessary
##########
hugegraph-client-go/hgtransport/hgtransport.go:
##########
@@ -0,0 +1,246 @@
+package hgtransport
+
+import (
+ "bytes"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "net/url"
+ "regexp"
+ "runtime"
+ "strings"
+ "time"
+
+ "hugegraph.apache.org/client-go/internal/version"
+)
+
+// Version returns the package version as a string.
+//
+const Version = version.Client
+
+var (
+ userAgent string
+ reGoVersion = regexp.MustCompile(`go(\d+\.\d+\..+)`)
+)
+
+func init() {
+ userAgent = initUserAgent()
+}
+
+// Interface defines the interface for HTTP client.
+//
+type Interface interface {
+ Perform(*http.Request) (*http.Response, error)
+}
+
+// Config represents the configuration of HTTP client.
+//
+type Config struct {
+ URL *url.URL
+ Username string
+ Password string
+ GraphSpace string
+ Graph string
+
+ Transport http.RoundTripper
+ Logger Logger
+}
+
+// Client represents the HTTP client.
+//
+type Client struct {
+ url *url.URL
+ username string
+ password string
+ graphspaces string
+ graph string
+
+ transport http.RoundTripper
+ logger Logger
+}
+
+// New creates new HTTP client.
+//
+// http.DefaultTransport will be used if no transport is passed in the configuration.
+//
+func New(cfg Config) *Client {
+ if cfg.Transport == nil {
+ cfg.Transport = http.DefaultTransport
+ }
+
+ return &Client{
+ url: cfg.URL,
+ username: cfg.Username,
+ password: cfg.Password,
+ graphspaces: cfg.GraphSpace,
+ graph: cfg.Graph,
+ transport: cfg.Transport,
+ logger: cfg.Logger,
+ }
+}
+
+// Perform executes the request and returns a response or error.
+//
+func (c *Client) Perform(req *http.Request) (*http.Response, error) {
+
+ u := c.url
+ c.setURL(u, req)
+ c.setUserAgent(req)
+ c.setHost(req)
+ c.setContentTypeJSON(req)
+ c.setGraph(req)
+ c.setGraphSpace(req)
+ c.setBodyGraphInfo(req)
+
+ if _, ok := req.Header["Authorization"]; !ok {
+ c.setBasicAuth(u, req)
+ }
+
+ fmt.Println(req.Header)
+ var dupReqBody *bytes.Buffer
+ if c.logger != nil && c.logger.RequestBodyEnabled() {
+ if req.Body != nil && req.Body != http.NoBody {
+ dupReqBody = bytes.NewBuffer(make([]byte, 0, int(req.ContentLength)))
+ dupReqBody.ReadFrom(req.Body)
+ req.Body = ioutil.NopCloser(bytes.NewBuffer(dupReqBody.Bytes()))
+ }
+ }
+ start := time.Now().UTC()
+ res, err := c.transport.RoundTrip(req)
+ dur := time.Since(start)
+ if c.logger != nil {
+ var dupRes http.Response
+ if res != nil {
+ dupRes = *res
+ }
+ if c.logger.RequestBodyEnabled() {
+ if req.Body != nil && req.Body != http.NoBody {
+ req.Body = ioutil.NopCloser(dupReqBody)
+ }
+ }
+ if c.logger.ResponseBodyEnabled() {
+ if res != nil && res.Body != nil && res.Body != http.NoBody {
+ b1, b2, _ := duplicateBody(res.Body)
+ dupRes.Body = b1
+ res.Body = b2
+ }
+ }
+ c.logger.LogRoundTrip(req, &dupRes, err, start, dur) // errcheck exclude
+ }
+
+ // TODO(karmi): Wrap error
+ return res, err
+}
+
+func (c *Client) setURL(u *url.URL, req *http.Request) *http.Request {
+ req.URL.Scheme = u.Scheme
+ req.URL.Host = u.Host
+
+ if u.Path != "" {
+ var b strings.Builder
+ b.Grow(len(u.Path) + len(req.URL.Path))
+ b.WriteString(u.Path)
+ b.WriteString(req.URL.Path)
+ req.URL.Path = b.String()
+ }
+
+ return req
+}
+
+func (c *Client) setBasicAuth(u *url.URL, req *http.Request) *http.Request {
+ if u.User != nil {
+ password, _ := u.User.Password()
+ req.SetBasicAuth(u.User.Username(), password)
+ return req
+ }
+
+ if c.username != "" && c.password != "" {
+ req.SetBasicAuth(c.username, c.password)
+ return req
+ }
+
+ return req
+}
+
+func (c *Client) setUserAgent(req *http.Request) *http.Request {
+ req.Header.Set("User-Agent", userAgent)
+ return req
+}
+
+func (c *Client) setHost(req *http.Request) *http.Request {
+ req.Header.Set("Host", req.URL.Host)
+ return req
+}
+
+func (c *Client) setContentTypeJSON(req *http.Request) *http.Request {
+ req.Header.Set("Content-Type", "application/json")
+ return req
+}
+
+func (c *Client) setGraph(req *http.Request) *http.Request {
+ req.URL.RawQuery = strings.ReplaceAll(req.URL.RawQuery, url.QueryEscape("${GRAPH_NAME}"), c.graph)
+ req.URL.Path = strings.ReplaceAll(req.URL.Path, "${GRAPH_NAME}", c.graph)
+ return req
+}
+
+func (c *Client) setGraphSpace(req *http.Request) *http.Request {
+ req.URL.RawQuery = strings.ReplaceAll(req.URL.RawQuery, url.QueryEscape("${GRAPH_SPACE_NAME}"), c.graphspaces)
+ req.URL.Path = strings.ReplaceAll(req.URL.Path, "${GRAPH_SPACE_NAME}", c.graphspaces)
+ return req
+}
+
+func (c *Client) setBodyGraphInfo(req *http.Request) *http.Request {
+ //
+ if req.Body == nil {
+ return req
+ }
+ body, err := ioutil.ReadAll(req.Body)
+ if err != nil {
+ return req
+ }
+ // 关闭 r.Body,因为我们已经读取了全部内容
+ req.Body.Close()
+ // 将字节切片转换成字符串
+ bodyStr := string(body)
+
+ // 是否需要替换
+ if strings.Contains(bodyStr, `"graph":"${GRAPH_SPACE_NAME}-${GRAPH_NAME}"`) {
Review Comment:
Why replace the body here instead of setting it when the request body is constructed?
##########
hugegraph-client-go/hgapi/hgapi.go:
##########
@@ -0,0 +1,45 @@
+package hgapi
+
+import (
+ "net/http"
+ "strconv"
+ "time"
+
+ "hugegraph.apache.org/client-go/internal/version"
+)
+
+// VERSION returns the package version as a string.
+//
+const VERSION = version.Client
+
+// Transport defines the interface for an API client.
+//
+type Transport interface {
+ Perform(*http.Request) (*http.Response, error)
+}
+
+// BoolPtr returns a pointer to v.
+//
+// It is used as a convenience function for converting a bool value
+// into a pointer when passing the value to a function or struct field
+// which expects a pointer.
+//
+func BoolPtr(v bool) *bool { return &v }
Review Comment:
can we direct use &v replace BoolPtr?
##########
hugegraph-client-go/README.en.md:
##########
@@ -0,0 +1,36 @@
+# hugegraph
+
+#### Description
+基于Go语言的hugegraph client SDK工具
Review Comment:
english description prefer
##########
hugegraph-client-go/Makefile:
##########
@@ -0,0 +1,58 @@
+# init project path
+HOMEDIR := $(shell pwd)
+OUTDIR := $(HOMEDIR)/output
+
+# 设置编译时所需要的 go 环境
+export GOENV = $(HOMEDIR)/go.env
+
+GO := go
+GOMOD := $(GO) mod
+GOBUILD := $(GO) build
+GOTEST := $(GO) test -race -timeout 30s -gcflags="-N -l"
+GOPKGS := $$($(GO) list ./...| grep -vE "vendor")
+
+# test cover files
+COVPROF := $(HOMEDIR)/covprof.out # coverage profile
+COVFUNC := $(HOMEDIR)/covfunc.txt # coverage profile information for each function
+COVHTML := $(HOMEDIR)/covhtml.html # HTML representation of coverage profile
+
+# make, make all
+all: prepare compile package
+
+set-env:
+ $(GO) env
+
+
+#make prepare, download dependencies
+prepare: gomod
+
+gomod: set-env
+ $(GOMOD) download -x || $(GOMOD) download -x
+
+#make compile
+compile: build
+
+build:
+ $(GOBUILD) -o $(HOMEDIR)/go-hugegraph
+
+# make test, test your code
+test: prepare test-case
+test-case:
+ $(GOTEST) -v -cover $(GOPKGS)
+
+# make package
+package: package-bin
+package-bin:
+ rm -rf $(OUTDIR)
+ mkdir -p $(OUTDIR)
+ mv go-hugegraph $(OUTDIR)/
+
+# make clean
+clean:
+ $(GO) clean
+ rm -rf $(OUTDIR)
+ rm -rf $(HOMEDIR)/go-hugegraph
+ rm -rf $(GOPATH)/pkg/darwin_amd64
+
+# avoid filename conflict and speed up build
+.PHONY: all prepare compile test package clean build
Review Comment:
gofmt missed
##########
hugegraph-client-go/Makefile:
##########
@@ -0,0 +1,58 @@
+# init project path
+HOMEDIR := $(shell pwd)
+OUTDIR := $(HOMEDIR)/output
+
+# 设置编译时所需要的 go 环境
+export GOENV = $(HOMEDIR)/go.env
+
+GO := go
+GOMOD := $(GO) mod
+GOBUILD := $(GO) build
+GOTEST := $(GO) test -race -timeout 30s -gcflags="-N -l"
+GOPKGS := $$($(GO) list ./...| grep -vE "vendor")
+
+# test cover files
+COVPROF := $(HOMEDIR)/covprof.out # coverage profile
+COVFUNC := $(HOMEDIR)/covfunc.txt # coverage profile information for each function
+COVHTML := $(HOMEDIR)/covhtml.html # HTML representation of coverage profile
+
+# make, make all
+all: prepare compile package
+
+set-env:
+ $(GO) env
+
+
+#make prepare, download dependencies
+prepare: gomod
+
+gomod: set-env
Review Comment:
why not GO111MODULE=on go mod tidy
##########
hugegraph-client-go/hgtransport/logger.go:
##########
@@ -0,0 +1,388 @@
+package hgtransport
+
+import (
+ "bufio"
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "net/http"
+ "net/url"
+ "strconv"
+ "strings"
+ "time"
+)
+
+// Logger defines an interface for logging request and response.
+//
+type Logger interface {
+ // LogRoundTrip should not modify the request or response, except for consuming and closing the body.
+ // Implementations have to check for nil values in request and response.
+ LogRoundTrip(*http.Request, *http.Response, error, time.Time, time.Duration) error
+ // RequestBodyEnabled makes the client pass a copy of request body to the logger.
+ RequestBodyEnabled() bool
+ // ResponseBodyEnabled makes the client pass a copy of response body to the logger.
+ ResponseBodyEnabled() bool
+}
+
+// TextLogger prints the log message in plain text.
+//
+type TextLogger struct {
+ Output io.Writer
+ EnableRequestBody bool
+ EnableResponseBody bool
+}
+
+// ColorLogger prints the log message in a terminal-optimized plain text.
+//
+type ColorLogger struct {
+ Output io.Writer
+ EnableRequestBody bool
+ EnableResponseBody bool
+}
+
+// CurlLogger prints the log message as a runnable curl command.
+//
+type CurlLogger struct {
+ Output io.Writer
+ EnableRequestBody bool
+ EnableResponseBody bool
+}
+
+// JSONLogger prints the log message as JSON.
+//
+type JSONLogger struct {
+ Output io.Writer
+ EnableRequestBody bool
+ EnableResponseBody bool
+}
+
+// LogRoundTrip prints the information about request and response.
+//
+func (l *TextLogger) LogRoundTrip(req *http.Request, res *http.Response, err error, start time.Time, dur time.Duration) error {
+ fmt.Fprintf(l.Output, "%s %s %s [status:%d request:%s]\n",
Review Comment:
why there need custom logger? why no use other logger framework?
##########
hugegraph-client-go/hgtransport/hgtransport.go:
##########
@@ -0,0 +1,246 @@
+package hgtransport
+
+import (
+ "bytes"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "net/url"
+ "regexp"
+ "runtime"
+ "strings"
+ "time"
+
+ "hugegraph.apache.org/client-go/internal/version"
+)
+
+// Version returns the package version as a string.
+//
+const Version = version.Client
+
+var (
+ userAgent string
+ reGoVersion = regexp.MustCompile(`go(\d+\.\d+\..+)`)
+)
+
+func init() {
+ userAgent = initUserAgent()
+}
+
+// Interface defines the interface for HTTP client.
+//
+type Interface interface {
+ Perform(*http.Request) (*http.Response, error)
+}
+
+// Config represents the configuration of HTTP client.
+//
+type Config struct {
+ URL *url.URL
+ Username string
+ Password string
+ GraphSpace string
+ Graph string
+
+ Transport http.RoundTripper
+ Logger Logger
+}
+
+// Client represents the HTTP client.
+//
+type Client struct {
+ url *url.URL
+ username string
+ password string
+ graphspaces string
+ graph string
+
+ transport http.RoundTripper
+ logger Logger
+}
+
+// New creates new HTTP client.
+//
+// http.DefaultTransport will be used if no transport is passed in the configuration.
+//
+func New(cfg Config) *Client {
+ if cfg.Transport == nil {
+ cfg.Transport = http.DefaultTransport
+ }
+
+ return &Client{
+ url: cfg.URL,
+ username: cfg.Username,
+ password: cfg.Password,
+ graphspaces: cfg.GraphSpace,
+ graph: cfg.Graph,
+ transport: cfg.Transport,
+ logger: cfg.Logger,
+ }
+}
+
+// Perform executes the request and returns a response or error.
+//
+func (c *Client) Perform(req *http.Request) (*http.Response, error) {
+
+ u := c.url
+ c.setURL(u, req)
+ c.setUserAgent(req)
+ c.setHost(req)
+ c.setContentTypeJSON(req)
+ c.setGraph(req)
+ c.setGraphSpace(req)
+ c.setBodyGraphInfo(req)
+
+ if _, ok := req.Header["Authorization"]; !ok {
+ c.setBasicAuth(u, req)
+ }
+
+ fmt.Println(req.Header)
+ var dupReqBody *bytes.Buffer
+ if c.logger != nil && c.logger.RequestBodyEnabled() {
+ if req.Body != nil && req.Body != http.NoBody {
+ dupReqBody = bytes.NewBuffer(make([]byte, 0, int(req.ContentLength)))
+ dupReqBody.ReadFrom(req.Body)
+ req.Body = ioutil.NopCloser(bytes.NewBuffer(dupReqBody.Bytes()))
+ }
+ }
+ start := time.Now().UTC()
+ res, err := c.transport.RoundTrip(req)
+ dur := time.Since(start)
+ if c.logger != nil {
+ var dupRes http.Response
+ if res != nil {
+ dupRes = *res
+ }
+ if c.logger.RequestBodyEnabled() {
+ if req.Body != nil && req.Body != http.NoBody {
+ req.Body = ioutil.NopCloser(dupReqBody)
+ }
+ }
+ if c.logger.ResponseBodyEnabled() {
+ if res != nil && res.Body != nil && res.Body != http.NoBody {
+ b1, b2, _ := duplicateBody(res.Body)
+ dupRes.Body = b1
+ res.Body = b2
+ }
+ }
+ c.logger.LogRoundTrip(req, &dupRes, err, start, dur) // errcheck exclude
+ }
+
+ // TODO(karmi): Wrap error
+ return res, err
+}
+
+func (c *Client) setURL(u *url.URL, req *http.Request) *http.Request {
+ req.URL.Scheme = u.Scheme
+ req.URL.Host = u.Host
+
+ if u.Path != "" {
+ var b strings.Builder
+ b.Grow(len(u.Path) + len(req.URL.Path))
+ b.WriteString(u.Path)
+ b.WriteString(req.URL.Path)
+ req.URL.Path = b.String()
+ }
+
+ return req
+}
+
+func (c *Client) setBasicAuth(u *url.URL, req *http.Request) *http.Request {
+ if u.User != nil {
+ password, _ := u.User.Password()
+ req.SetBasicAuth(u.User.Username(), password)
+ return req
+ }
+
+ if c.username != "" && c.password != "" {
+ req.SetBasicAuth(c.username, c.password)
+ return req
+ }
+
+ return req
+}
+
+func (c *Client) setUserAgent(req *http.Request) *http.Request {
+ req.Header.Set("User-Agent", userAgent)
+ return req
+}
+
+func (c *Client) setHost(req *http.Request) *http.Request {
+ req.Header.Set("Host", req.URL.Host)
+ return req
+}
+
+func (c *Client) setContentTypeJSON(req *http.Request) *http.Request {
+ req.Header.Set("Content-Type", "application/json")
+ return req
+}
+
+func (c *Client) setGraph(req *http.Request) *http.Request {
+ req.URL.RawQuery = strings.ReplaceAll(req.URL.RawQuery, url.QueryEscape("${GRAPH_NAME}"), c.graph)
+ req.URL.Path = strings.ReplaceAll(req.URL.Path, "${GRAPH_NAME}", c.graph)
+ return req
+}
+
+func (c *Client) setGraphSpace(req *http.Request) *http.Request {
+ req.URL.RawQuery = strings.ReplaceAll(req.URL.RawQuery, url.QueryEscape("${GRAPH_SPACE_NAME}"), c.graphspaces)
+ req.URL.Path = strings.ReplaceAll(req.URL.Path, "${GRAPH_SPACE_NAME}", c.graphspaces)
+ return req
+}
+
+func (c *Client) setBodyGraphInfo(req *http.Request) *http.Request {
+ //
+ if req.Body == nil {
+ return req
+ }
+ body, err := ioutil.ReadAll(req.Body)
+ if err != nil {
+ return req
+ }
+ // 关闭 r.Body,因为我们已经读取了全部内容
+ req.Body.Close()
+ // 将字节切片转换成字符串
+ bodyStr := string(body)
+
+ // 是否需要替换
+ if strings.Contains(bodyStr, `"graph":"${GRAPH_SPACE_NAME}-${GRAPH_NAME}"`) {
Review Comment:
Why replace the body here instead of setting it when the request body is constructed?
##########
hugegraph-client-go/hgtransport/hgtransport.go:
##########
@@ -0,0 +1,246 @@
+package hgtransport
+
+import (
+ "bytes"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "net/url"
+ "regexp"
+ "runtime"
+ "strings"
+ "time"
+
+ "hugegraph.apache.org/client-go/internal/version"
+)
+
+// Version returns the package version as a string.
+//
+const Version = version.Client
+
+var (
+ userAgent string
+ reGoVersion = regexp.MustCompile(`go(\d+\.\d+\..+)`)
+)
+
+func init() {
+ userAgent = initUserAgent()
+}
+
+// Interface defines the interface for HTTP client.
+//
+type Interface interface {
+ Perform(*http.Request) (*http.Response, error)
+}
+
+// Config represents the configuration of HTTP client.
+//
+type Config struct {
+ URL *url.URL
+ Username string
+ Password string
+ GraphSpace string
+ Graph string
+
+ Transport http.RoundTripper
+ Logger Logger
+}
+
+// Client represents the HTTP client.
+//
+type Client struct {
+ url *url.URL
+ username string
+ password string
+ graphspaces string
+ graph string
+
+ transport http.RoundTripper
+ logger Logger
+}
+
+// New creates new HTTP client.
+//
+// http.DefaultTransport will be used if no transport is passed in the configuration.
+//
+func New(cfg Config) *Client {
+ if cfg.Transport == nil {
+ cfg.Transport = http.DefaultTransport
+ }
+
+ return &Client{
+ url: cfg.URL,
+ username: cfg.Username,
+ password: cfg.Password,
+ graphspaces: cfg.GraphSpace,
+ graph: cfg.Graph,
+ transport: cfg.Transport,
+ logger: cfg.Logger,
+ }
+}
+
+// Perform executes the request and returns a response or error.
+//
+func (c *Client) Perform(req *http.Request) (*http.Response, error) {
Review Comment:
This method is to forward the business request to the backend. The request parameter here is net.httprequest, so here it should be to call http directly. It is better not to have business processing. Authorization and monitoring can be viewed here, but it is best to modify the request body It is best to do it when constructing httpRequest
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
[GitHub] [incubator-hugegraph-toolchain] zyxxoo commented on a diff in pull request #514: feature : add go client
Posted by "zyxxoo (via GitHub)" <gi...@apache.org>.
zyxxoo commented on code in PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#discussion_r1309521105
##########
hugegraph-client-go/Makefile:
##########
@@ -0,0 +1,58 @@
+# init project path
+HOMEDIR := $(shell pwd)
+OUTDIR := $(HOMEDIR)/output
+
+# 设置编译时所需要的 go 环境
+export GOENV = $(HOMEDIR)/go.env
+
+GO := go
+GOMOD := $(GO) mod
+GOBUILD := $(GO) build
+GOTEST := $(GO) test -race -timeout 30s -gcflags="-N -l"
+GOPKGS := $$($(GO) list ./...| grep -vE "vendor")
+
+# test cover files
+COVPROF := $(HOMEDIR)/covprof.out # coverage profile
+COVFUNC := $(HOMEDIR)/covfunc.txt # coverage profile information for each function
+COVHTML := $(HOMEDIR)/covhtml.html # HTML representation of coverage profile
+
+# make, make all
+all: prepare compile package
+
+set-env:
+ $(GO) env
+
+
+#make prepare, download dependencies
+prepare: gomod
+
+gomod: set-env
+ $(GOMOD) download -x || $(GOMOD) download -x
+
+#make compile
+compile: build
+
+build:
+ $(GOBUILD) -o $(HOMEDIR)/go-hugegraph
Review Comment:
GO111MODULE=on
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
[GitHub] [incubator-hugegraph-toolchain] javeme commented on pull request #514: feature : add go client
Posted by "javeme (via GitHub)" <gi...@apache.org>.
javeme commented on PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#issuecomment-1712698170
Is it still in progress?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
[GitHub] [incubator-hugegraph-toolchain] izliang commented on pull request #514: feature : add go client
Posted by "izliang (via GitHub)" <gi...@apache.org>.
izliang commented on PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#issuecomment-1722406690
In process
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feature(client): support go client for hugegraph [incubator-hugegraph-toolchain]
Posted by "javeme (via GitHub)" <gi...@apache.org>.
javeme commented on PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#issuecomment-1777202404
I think it’s OK to keep the style of Go language
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feature(client): support go client for hugegraph [incubator-hugegraph-toolchain]
Posted by "hankwenyx (via GitHub)" <gi...@apache.org>.
hankwenyx commented on code in PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#discussion_r1366426783
##########
hugegraph-client-go/api/v1/api.version.go:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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"
+ "io"
+ "io/ioutil"
+ "net/http"
+
+ "hugegraph.apache.org/client-go/api"
+)
+
+// ----- API Definition -------------------------------------------------------
+
+// 查看HugeGraph的版本信息
+//
+// See full documentation at https://hugegraph.apache.org/cn/docs/clients/restful-api/other/#1011-%E6%9F%A5%E7%9C%8Bhugegraph%E7%9A%84%E7%89%88%E6%9C%AC%E4%BF%A1%E6%81%AF
+func newVersionFunc(t api.Transport) Version {
+ return func(o ...func(*VersionRequest)) (*VersionResponse, error) {
+ var r = VersionRequest{}
+ for _, f := range o {
+ f(&r)
+ }
+ return r.Do(r.ctx, t)
+ }
+}
+
+type Version func(o ...func(*VersionRequest)) (*VersionResponse, error)
+
+type VersionRequest struct {
+ Body io.Reader
+ ctx context.Context
+}
+
+type VersionResponse struct {
+ StatusCode int `json:"-"`
+ Header http.Header `json:"-"`
+ Body io.ReadCloser `json:"-"`
+ Versions VersionResponseData `json:"versions"`
+}
+
+type VersionResponseData struct {
+ Version string `json:"version"`
+ Core string `json:"core"`
+ Gremlin string `json:"gremlin"`
+ API string `json:"api"`
+}
+
+func (r VersionRequest) Do(ctx context.Context, transport api.Transport) (*VersionResponse, error) {
+
+ req, _ := api.NewRequest("GET", "/versions", r.Body)
Review Comment:
when returning pointer variables, it's better not to ignore error handling
##########
hugegraph-client-go/api/api.response.go:
##########
Review Comment:
Go follows a convention where source files are all lower case with underscore separating multiple words. why not use api_response.go?other source files have the same question.
##########
hugegraph-client-go/api/v1/api.version.go:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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"
+ "io"
+ "io/ioutil"
+ "net/http"
+
+ "hugegraph.apache.org/client-go/api"
+)
+
+// ----- API Definition -------------------------------------------------------
+
+// 查看HugeGraph的版本信息
+//
+// See full documentation at https://hugegraph.apache.org/cn/docs/clients/restful-api/other/#1011-%E6%9F%A5%E7%9C%8Bhugegraph%E7%9A%84%E7%89%88%E6%9C%AC%E4%BF%A1%E6%81%AF
+func newVersionFunc(t api.Transport) Version {
+ return func(o ...func(*VersionRequest)) (*VersionResponse, error) {
+ var r = VersionRequest{}
+ for _, f := range o {
+ f(&r)
+ }
+ return r.Do(r.ctx, t)
+ }
+}
+
+type Version func(o ...func(*VersionRequest)) (*VersionResponse, error)
+
+type VersionRequest struct {
+ Body io.Reader
+ ctx context.Context
+}
+
+type VersionResponse struct {
+ StatusCode int `json:"-"`
+ Header http.Header `json:"-"`
+ Body io.ReadCloser `json:"-"`
+ Versions VersionResponseData `json:"versions"`
+}
+
+type VersionResponseData struct {
+ Version string `json:"version"`
+ Core string `json:"core"`
+ Gremlin string `json:"gremlin"`
+ API string `json:"api"`
+}
+
+func (r VersionRequest) Do(ctx context.Context, transport api.Transport) (*VersionResponse, error) {
+
+ req, _ := api.NewRequest("GET", "/versions", r.Body)
+
+ if ctx != nil {
+ req = req.WithContext(ctx)
+ }
+
+ res, err := transport.Perform(req)
+ if err != nil {
+ return nil, err
Review Comment:
It is recommended to wrap the error returned by the lower level function and return it. You can add some parameter information for debugging.
##########
hugegraph-client-go/api/api.response.go:
##########
Review Comment:
Go follows a convention where source files are all lower case with underscore separating multiple words. why not use api_response.go?other source files have the same question.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feature(client): support go client for hugegraph [incubator-hugegraph-toolchain]
Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin commented on code in PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#discussion_r1366480922
##########
pom.xml:
##########
@@ -28,7 +28,8 @@
<name>${project.artifactId}</name>
<url>https://github.com/apache/incubator-hugegraph-toolchain</url>
<description>
- hugegraph-toolchain is the integration project of a series of utilities for HugeGraph, it includes 4 main modules (loader/hubble/tools/client)
+ hugegraph-toolchain is the integration project of a series of utilities for HugeGraph, it
+ includes 4 main modules (loader/hubble/tools/client)
Review Comment:
> seems don't need to wrap line
Too long to read & break the auto-format rule, if it **doesn't affect the pom attribute** of the function, it is better to wrap line by 100 characters rather than put them in a LONG line
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feature(client): support go client for hugegraph [incubator-hugegraph-toolchain]
Posted by "izliang (via GitHub)" <gi...@apache.org>.
izliang commented on code in PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#discussion_r1368310622
##########
hugegraph-client-go/api/api.response.go:
##########
Review Comment:
Normally, in Go language, underline is used as the file separator. Here, because the API is a tree structure, English commas are used to distinguish between trees, and then underline is used for segmentation. For example: api.veretx.create.go and api.vertex.get_ By_ The use of English commas and underscores in id.go is more conducive to presentation and layering.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feature(client): support go client for hugegraph [incubator-hugegraph-toolchain]
Posted by "izliang (via GitHub)" <gi...@apache.org>.
izliang commented on code in PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#discussion_r1368312167
##########
hugegraph-client-go/api/v1/api.version.go:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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"
+ "io"
+ "io/ioutil"
+ "net/http"
+
+ "hugegraph.apache.org/client-go/api"
+)
+
+// ----- API Definition -------------------------------------------------------
+
+// 查看HugeGraph的版本信息
+//
+// See full documentation at https://hugegraph.apache.org/cn/docs/clients/restful-api/other/#1011-%E6%9F%A5%E7%9C%8Bhugegraph%E7%9A%84%E7%89%88%E6%9C%AC%E4%BF%A1%E6%81%AF
+func newVersionFunc(t api.Transport) Version {
+ return func(o ...func(*VersionRequest)) (*VersionResponse, error) {
+ var r = VersionRequest{}
+ for _, f := range o {
+ f(&r)
+ }
+ return r.Do(r.ctx, t)
+ }
+}
+
+type Version func(o ...func(*VersionRequest)) (*VersionResponse, error)
+
+type VersionRequest struct {
+ Body io.Reader
+ ctx context.Context
+}
+
+type VersionResponse struct {
+ StatusCode int `json:"-"`
+ Header http.Header `json:"-"`
+ Body io.ReadCloser `json:"-"`
+ Versions VersionResponseData `json:"versions"`
+}
+
+type VersionResponseData struct {
+ Version string `json:"version"`
+ Core string `json:"core"`
+ Gremlin string `json:"gremlin"`
+ API string `json:"api"`
+}
+
+func (r VersionRequest) Do(ctx context.Context, transport api.Transport) (*VersionResponse, error) {
+
+ req, _ := api.NewRequest("GET", "/versions", r.Body)
+
+ if ctx != nil {
+ req = req.WithContext(ctx)
+ }
+
+ res, err := transport.Perform(req)
+ if err != nil {
+ return nil, err
Review Comment:
Due to the fact that many APIs have not yet been implemented, it is currently not possible to clearly enumerate all internal errors. Therefore, HTTP errors are currently being used and transmitted upwards.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
[GitHub] [incubator-hugegraph-toolchain] zyxxoo commented on a diff in pull request #514: feature : add go client
Posted by "zyxxoo (via GitHub)" <gi...@apache.org>.
zyxxoo commented on code in PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#discussion_r1309541625
##########
hugegraph-client-go/README.en.md:
##########
@@ -0,0 +1,36 @@
+# hugegraph
+
+#### Description
+基于Go语言的hugegraph client SDK工具
Review Comment:
english description prefer(later,or keep both en & cn version)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
[GitHub] [incubator-hugegraph-toolchain] codecov[bot] commented on pull request #514: feature : add go client
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#issuecomment-1695585653
## [Codecov](https://app.codecov.io/gh/apache/incubator-hugegraph-toolchain/pull/514?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
> Merging [#514](https://app.codecov.io/gh/apache/incubator-hugegraph-toolchain/pull/514?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (5789511) into [master](https://app.codecov.io/gh/apache/incubator-hugegraph-toolchain/commit/d9f234ae97107f22cb020dcef073d1b8596b6ed7?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (d9f234a) will **not change** coverage.
> Report is 1 commits behind head on master.
> The diff coverage is `n/a`.
```diff
@@ Coverage Diff @@
## master #514 +/- ##
=========================================
Coverage 62.42% 62.42%
Complexity 895 895
=========================================
Files 91 91
Lines 4404 4404
Branches 519 519
=========================================
Hits 2749 2749
Misses 1450 1450
Partials 205 205
```
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
[GitHub] [incubator-hugegraph-toolchain] izliang commented on a diff in pull request #514: feature : add go client
Posted by "izliang (via GitHub)" <gi...@apache.org>.
izliang commented on code in PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#discussion_r1328052389
##########
hugegraph-client-go/hgtransport/hgtransport.go:
##########
@@ -0,0 +1,246 @@
+package hgtransport
+
+import (
+ "bytes"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "net/url"
+ "regexp"
+ "runtime"
+ "strings"
+ "time"
+
+ "hugegraph.apache.org/client-go/internal/version"
+)
+
+// Version returns the package version as a string.
+//
+const Version = version.Client
+
+var (
+ userAgent string
+ reGoVersion = regexp.MustCompile(`go(\d+\.\d+\..+)`)
+)
+
+func init() {
+ userAgent = initUserAgent()
+}
+
+// Interface defines the interface for HTTP client.
+//
+type Interface interface {
+ Perform(*http.Request) (*http.Response, error)
+}
+
+// Config represents the configuration of HTTP client.
+//
+type Config struct {
+ URL *url.URL
+ Username string
+ Password string
+ GraphSpace string
+ Graph string
+
+ Transport http.RoundTripper
+ Logger Logger
+}
+
+// Client represents the HTTP client.
+//
+type Client struct {
+ url *url.URL
+ username string
+ password string
+ graphspaces string
+ graph string
+
+ transport http.RoundTripper
+ logger Logger
+}
+
+// New creates new HTTP client.
+//
+// http.DefaultTransport will be used if no transport is passed in the configuration.
+//
+func New(cfg Config) *Client {
+ if cfg.Transport == nil {
+ cfg.Transport = http.DefaultTransport
+ }
+
+ return &Client{
+ url: cfg.URL,
+ username: cfg.Username,
+ password: cfg.Password,
+ graphspaces: cfg.GraphSpace,
+ graph: cfg.Graph,
+ transport: cfg.Transport,
+ logger: cfg.Logger,
+ }
+}
+
+// Perform executes the request and returns a response or error.
+//
+func (c *Client) Perform(req *http.Request) (*http.Response, error) {
Review Comment:
Okay, during the debugging process, I found that some APIs needed to modify the information in the request body, such as graph space and graph name, so I made the modifications. I'll think about how to solve this problem
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feature(client): support go client for hugegraph [incubator-hugegraph-toolchain]
Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin commented on PR #514:
URL: https://github.com/apache/incubator-hugegraph-toolchain/pull/514#issuecomment-1774810340
Although I have replaced all tab to 4 spaces, I found this rule is set by `go fmt` by default(the official format tool), Its design concept is to use tabs for line breaks and **spaces** for alignment[1]
This means that we need to show a reminder to inform the devs that `USE space` & `4 spaces` need to be **specified** for go here. Additionally, if go projects generally use **8 spaces** for indentation, we can consider continuing to use 8 spaces instead of 4, or maybe use the **default config with tab** instead @javeme @zyxxoo?
And I checked some go projects in apache, seems they also use TAB(1 tab = 8 space) for default.
Refer:
1. apache [dubbo-go](https://github.com/apache/dubbo-go/blob/main/tools/dubbogo-cli/generator/application/gomod.go)
2. https://github.com/apache/incubator-answer/blob/main/cmd/command.go
3. https://github.com/apache/incubator-devlake/blob/main/backend/test/e2e/manual/pagerduty/models.go
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org