Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(client): support go client for hugegraph #514

Merged
merged 38 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
dddcc66
init go client
izliang Aug 27, 2023
6624859
go client ci
izliang Aug 27, 2023
2c68f82
Update client-go-ci.yml
izliang Aug 27, 2023
5789511
Update client-go-ci.yml
izliang Aug 27, 2023
3103dbe
fix client-go
izliang Oct 16, 2023
a537d72
set License Header
izliang Oct 16, 2023
09cc5c4
fix package name
izliang Oct 16, 2023
6d0a547
add ignore license header
izliang Oct 16, 2023
99891c6
fix RAT check & markdown format
imbajin Oct 17, 2023
a034043
set license header
izliang Oct 17, 2023
06ed677
fix api
izliang Oct 23, 2023
d431311
fix api
izliang Oct 23, 2023
2bf495b
chore: replace all tab to 4 space
imbajin Oct 23, 2023
94e5d98
Update client-go-ci.yml
izliang Oct 23, 2023
2ab0e45
Update client-go-ci.yml
izliang Oct 24, 2023
580c755
fix makefile
izliang Oct 25, 2023
b0324dc
Merge branch 'master' into pr/514
imbajin Oct 30, 2023
df4f0e7
fix package name
izliang Oct 30, 2023
7888ca9
add Gremlin post API
izliang Oct 31, 2023
0b454f5
add property apis
izliang Nov 1, 2023
cc1d465
add apis
izliang Nov 1, 2023
5513534
add vertexlabel apis
izliang Nov 1, 2023
d58bc58
fix file header
izliang Nov 2, 2023
bb5a703
set username & password
izliang Nov 2, 2023
f3e71a2
vertex API init
izliang Nov 10, 2023
0dfaedb
new API format
izliang Nov 16, 2023
a407393
API format
izliang Nov 17, 2023
fd2e747
fix API
izliang Nov 17, 2023
9495bc5
ADD API
izliang Nov 21, 2023
733333e
Fix Header
izliang Nov 22, 2023
f417238
set new CommitId
izliang Dec 4, 2023
47bee4c
Update client-go-ci.yml
izliang Dec 4, 2023
0c6a996
Update client-go-ci.yml
izliang Dec 4, 2023
74b76b6
Merge branch 'master' into pr/514
imbajin Dec 5, 2023
3c39403
Merge branch 'master' into feature-go-client
imbajin Dec 5, 2023
04469a0
Fix API
izliang Dec 10, 2023
e2050cc
Merge branch 'master' into pr/514
imbajin Dec 11, 2023
22b9c3d
tiny fix
imbajin Dec 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/client-go-ci.yml
Original file line number Diff line number Diff line change
@@ -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
izliang marked this conversation as resolved.
Show resolved Hide resolved
58 changes: 58 additions & 0 deletions hugegraph-client-go/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# init project path
HOMEDIR := $(shell pwd)
OUTDIR := $(HOMEDIR)/output

# 设置编译时所需要的 go 环境
izliang marked this conversation as resolved.
Show resolved Hide resolved
export GOENV = $(HOMEDIR)/go.env

GO := go
izliang marked this conversation as resolved.
Show resolved Hide resolved
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:
izliang marked this conversation as resolved.
Show resolved Hide resolved
$(GO) env


#make prepare, download dependencies
prepare: gomod

gomod: set-env
izliang marked this conversation as resolved.
Show resolved Hide resolved
izliang marked this conversation as resolved.
Show resolved Hide resolved
$(GOMOD) download -x || $(GOMOD) download -x

#make compile
compile: build

build:
$(GOBUILD) -o $(HOMEDIR)/go-hugegraph
izliang marked this conversation as resolved.
Show resolved Hide resolved

# 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
izliang marked this conversation as resolved.
Show resolved Hide resolved
36 changes: 36 additions & 0 deletions hugegraph-client-go/README.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# hugegraph

#### Description
基于Go语言的hugegraph client SDK工具
izliang marked this conversation as resolved.
Show resolved Hide resolved

#### Software Architecture
Software architecture description

#### Installation

1. xxxx
2. xxxx
3. xxxx

#### Instructions

1. xxxx
2. xxxx
3. xxxx

#### Contribution

1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request


#### Gitee Feature

1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
4. The most valuable open source project [GVP](https://gitee.com/gvp)
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
93 changes: 93 additions & 0 deletions hugegraph-client-go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# go-hugegraph

#### 介绍
基于Go语言的hugegraph client SDK工具

#### 软件架构
软件架构说明


#### 安装教程
```shell
go get github.com/go-hugegraph
```

#### 实现API


|API|说明|
|--|--|
|schema|获取模型schema|
|version|获取版本信息|


#### 使用说明

##### 1.初始化客户端
```go
package main

import "github.com/izliang/hugegraph"
import "github.com/izliang/hugegraph/hgtransport"

func main() {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused blank line?

clinet,err := hugegraph.NewClient(hugegraph.Config{
Host: "127.0.0.1",
izliang marked this conversation as resolved.
Show resolved Hide resolved
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)
izliang marked this conversation as resolved.
Show resolved Hide resolved
}
defer res.Body.Close()

fmt.Println(res.Versions)

fmt.Println(res.Versions.Version)
}

```
- 2.结果集响应体
izliang marked this conversation as resolved.
Show resolved Hide resolved
```go
type VersionResponse struct {
Versions struct {
Version string `json:"version"`
Core string `json:"core"`
Gremlin string `json:"gremlin"`
API string `json:"api"`
} `json:"versions"`
}

```
2. xxxx
3. xxxx

#### 参与贡献

1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request


#### 特技
4 changes: 4 additions & 0 deletions hugegraph-client-go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module hugegraph.apache.org/client-go

go 1.18

16 changes: 16 additions & 0 deletions hugegraph-client-go/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI=
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd h1:1FjCyPC+syAzJ5/2S8fqdZK1R22vvA0J7JZKcuOIQ7Y=
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg=
github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
github.com/ianlancetaylor/demangle v0.0.0-20211126204342-3ad08eb09c01 h1:+0qIm4/XbPn2PYkj6QM6CX/FJN5DGvFOaMkSyB1xuh8=
github.com/ianlancetaylor/demangle v0.0.0-20211126204342-3ad08eb09c01/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
45 changes: 45 additions & 0 deletions hugegraph-client-go/hgapi/hgapi.go
Original file line number Diff line number Diff line change
@@ -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 }
izliang marked this conversation as resolved.
Show resolved Hide resolved

// 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 }
izliang marked this conversation as resolved.
Show resolved Hide resolved

// formatDuration converts duration to a string in the format
// accepted by Elasticsearch.
//
func formatDuration(d time.Duration) string {
if d < time.Millisecond {
return strconv.FormatInt(int64(d), 10) + "nanos"
}
return strconv.FormatInt(int64(d)/int64(time.Millisecond), 10) + "ms"
}
Loading
Loading