Closed 1280019840 closed 4 weeks ago
To resolve the issue with the model
package and correctly create a vertex using the Vertex
struct in Go, you need to ensure that you import the model
package correctly. The model
package is an internal package in the HugeGraph toolchain. Here is how you can import it and use it to create a vertex:
model
package:import "hugegraph.apache.org/client-go/internal/model"
model.Vertex
struct:Here is an example of how to create a vertex using the model.Vertex
struct and the client.Vertex.Create
method:
package main
import (
"context"
"fmt"
"log"
"hugegraph.apache.org/client-go/api"
"hugegraph.apache.org/client-go/api/v1/vertex"
"hugegraph.apache.org/client-go/internal/model"
)
func main() {
// Initialize the transport (assuming you have a transport implementation)
var transport api.Transport
// Create a new Vertex client
vertexClient := vertex.New(transport)
// Define a new vertex
newVertex := model.Vertex[any]{
Label: "person",
Properties: map[string]any{
"name": "Alice",
"age": 30,
},
}
// Create the vertex
createResp, err := vertexClient.Create(
vertexClient.Create.WithContext(context.Background()),
vertexClient.Create.WithVertex(newVertex),
)
if err != nil {
log.Println("Error creating vertex:", err)
return
}
// Print the created vertex response
fmt.Println("createResp: ", createResp.StatusCode)
}
This example demonstrates how to import the model
package, define a new vertex, and create it using the client.Vertex.Create
method. Ensure that you have the correct import path for the model
package and that your transport implementation is correctly set up.
For more details, you can refer to the HugeGraph-Client Quick Start Guide [1][2].
To continue talking to Dosu, mention @dosu.
import "hugegraph.apache.org/client-go/internal/model" Packet does not exist
Problem Type (问题类型)
configs (配置项 / 文档相关)
Before submit
Environment (环境信息)
Your Question (问题描述)
Model is an internal package model, how should I create it Create a model when using Vertex Using Vertex [any] as a parameter, call Vertex What about Create. WithVertex
![image](https://github.com/apache/incubator-hugegraph-toolchain/assets/136102971/3a44d461-c9f2-4e40-b1ae-bd2109d4bced)
Vertex/Edge example (问题点 / 边数据举例)
Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)
No response