Closed 1280019840 closed 2 months ago
To properly create and use the model.Vertex
in your Go project, you need to ensure that you import the model
package correctly. The "undeclared name: model" compilation error indicates that the model
package is not recognized in your current file.
Here is an example of how you can import and use the model.Vertex
struct:
model
package at the beginning of your Go file.model.Vertex
.Assuming your project structure is as follows:
your_project/
├── main.go
└── hugegraph-client-go/
└── internal/
└── model/
└── model.go
Your main.go
file should look something like this:
package main
import (
"fmt"
"your_project/hugegraph-client-go/internal/model"
)
func main() {
// Example of creating a Vertex with properties of type map[string]interface{}
vertex := model.Vertex[map[string]interface{}]{
ID: "1",
Label: "person",
Properties: map[string]interface{}{
"name": "John Doe",
"age": 30,
},
}
fmt.Printf("Vertex: %+v\n", vertex)
}
In this example:
model
package is imported using the path relative to your main.go
file.model.Vertex
instance is created with properties of type map[string]interface{}
.Make sure the import path matches the actual location of your model
package. Adjust the import path if your project structure is different.
Additionally, if you are using the hugegraph-client-go
library, you might need to import the vertex
package and use its functions to create and manipulate vertices. Here is an example:
package main
import (
"context"
"fmt"
"github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/api"
"github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/api/v1/vertex"
"github.com/apache/incubator-hugegraph-toolchain/hugegraph-client-go/internal/model"
)
type Person struct {
Name string `json:"name,omitempty"`
Age uint64 `json:"age,omitempty"`
City string `json:"city,omitempty"`
}
func main() {
transport := api.NewTransport(api.Config{
Graph: "your_graph",
})
vertexClient := vertex.New(transport)
// Create a new vertex
person := Person{
Name: "John Doe",
Age: 30,
City: "New York",
}
createResp, err := vertexClient.Create(
vertexClient.Create.WithContext(context.Background()),
vertexClient.Create.WithVertex(model.Vertex[any]{
Label: "person",
Properties: person,
}),
)
if err != nil {
fmt.Println("Error creating vertex:", err)
return
}
fmt.Printf("Created Vertex: %+v\n", createResp.Data)
}
In this example:
vertex
package from the hugegraph-client-go
library is imported.vertex.Client
instance is created using the New
function.Create
method of the vertex.Client
.Ensure that you have the correct import paths and that the hugegraph-client-go
library is properly installed in your project [1][2][3].
To continue talking to Dosu, mention @dosu.
I am aware of this issue, please give me some time. I plan to reorganize the logic and design a more user-friendly SDK.
Due to the lack of activity, the current issue is marked as stale and will be closed after 20 days, any update will remove the stale label
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
Vertex/Edge example (问题点 / 边数据举例)
No response
Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)
No response