Skip to content

Version 1.5 of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot. For up-to-date documentation, see the latest version.

HugeGraph Go Client Quick Start

A HugeGraph Client SDK tool based on the Go language.

Software Architecture

(Software architecture description)

Installation Tutorial

1go get github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go

Implemented APIs

APIDescription
schemaGet schema information
versionGet version information

Usage Instructions

1. Initialize the Client

 1package main
 2
 3import (
 4	"log"
 5	"os"
 6
 7	"github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go"
 8	"github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/hgtransport"
 9)
10
11func main() {
12	client, err := hugegraph.NewCommonClient(hugegraph.Config{
13		Host:     "127.0.0.1",
14		Port:     8080,
15		Graph:    "hugegraph",
16		Username: "", // Fill in the username according to the actual situation
17		Password: "", // Fill in the password according to the actual situation
18		Logger: &hgtransport.ColorLogger{
19			Output:             os.Stdout,
20			EnableRequestBody:  true,
21			EnableResponseBody: true,
22		},
23	})
24
25	if err != nil {
26		log.Fatalf("Error creating the client: %s\n", err)
27	}
28
29	// Use the client for operations...
30	_ = client // Avoid "imported and not used" error
31}

2. Get HugeGraph Version

Get Version Information Using SDK

 1package main
 2
 3import (
 4	"fmt"
 5	"log"
 6	"os"
 7
 8	"github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go"
 9	"github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/hgtransport"
10)
11
12// initClient initializes and returns a HugeGraph client instance
13func initClient() *hugegraph.CommonClient {
14	client, err := hugegraph.NewCommonClient(hugegraph.Config{
15		Host:     "127.0.0.1",
16		Port:     8080,
17		Graph:    "hugegraph",
18		Username: "",
19		Password: "",
20		Logger: &hgtransport.ColorLogger{
21			Output:             os.Stdout,
22			EnableRequestBody:  true,
23			EnableResponseBody: true,
24		},
25	})
26	if err != nil {
27		log.Fatalf("Error creating the client: %s\n", err)
28	}
29	return client
30}
31
32func getVersion() {
33	client := initClient()
34	// Assume client has a Version method that returns version information and an error
35	// res, err := client.Version() // Actual call
36	// Simulate return, as the client.Version() return type in the original README does not fully match the usage here
37	type VersionInfo struct {
38		Versions struct {
39			Version string `json:"version"`
40			Core    string `json:"core"`
41			Gremlin string `json:"gremlin"`
42			API     string `json:"api"`
43		} `json:"versions"`
44		// Body io.ReadCloser // Assume there is a Body to close, adjust according to the actual SDK
45	}
46
47	// Simulate API call and return
48	res := &VersionInfo{
49		Versions: struct {
50			Version string `json:"version"`
51			Core    string `json:"core"`
52			Gremlin string `json:"gremlin"`
53			API     string `json:"api"`
54		}{
55			Version: "1.0.0", // Example version
56			Core:    "1.0.0",
57			Gremlin: "3.x.x",
58			API:     "v1",
59		},
60	}
61	// err := error(nil) // Assume no error
62
63	// if err != nil {
64	// 	log.Fatalf("Error getting the response: %s\n", err)
65	// }
66	// defer res.Body.Close() // If there is a Body, it needs to be closed
67
68	fmt.Println(res.Versions)
69	fmt.Println(res.Versions.Version)
70}
71
72func main() {
73	getVersion()
74}

Structure of the Return Value

 1package main
 2
 3// VersionResponse defines the structure returned by the version API
 4type VersionResponse struct {
 5	Versions struct {
 6		Version string `json:"version"` // hugegraph version
 7		Core    string `json:"core"`    // hugegraph core version
 8		Gremlin string `json:"gremlin"` // hugegraph gremlin version
 9		API     string `json:"api"`     // hugegraph api version
10	} `json:"versions"`
11}

API Reference