mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
Summary: Pull Request resolved: https://github.com/facebookexternal/fbc/pull/1192 Pull Request resolved: https://github.com/facebookincubator/ent/pull/11 Reviewed By: alexsn Differential Revision: D16377224 fbshipit-source-id: 07ca7436eb9b64fbe2299568560b91466b2417ba
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package graph
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"fbc/ent/dialect/gremlin/encoding/graphson"
|
|
)
|
|
|
|
// Vertex represents a graph vertex.
|
|
type Vertex struct {
|
|
Element
|
|
}
|
|
|
|
// NewVertex create a new graph vertex.
|
|
func NewVertex(id interface{}, label string) Vertex {
|
|
if label == "" {
|
|
label = "vertex"
|
|
}
|
|
return Vertex{
|
|
Element: NewElement(id, label),
|
|
}
|
|
}
|
|
|
|
// GraphsonType implements graphson.Typer interface.
|
|
func (Vertex) GraphsonType() graphson.Type {
|
|
return "g:Vertex"
|
|
}
|
|
|
|
// String implements fmt.Stringer interface.
|
|
func (v Vertex) String() string {
|
|
return fmt.Sprintf("v[%v]", v.ID)
|
|
}
|
|
|
|
// VertexProperty denotes a key/value pair associated with a vertex.
|
|
type VertexProperty struct {
|
|
ID interface{} `json:"id"`
|
|
Key string `json:"label"`
|
|
Value interface{} `json:"value"`
|
|
}
|
|
|
|
// NewVertexProperty create a new graph vertex property.
|
|
func NewVertexProperty(id interface{}, key string, value interface{}) VertexProperty {
|
|
return VertexProperty{
|
|
ID: id,
|
|
Key: key,
|
|
Value: value,
|
|
}
|
|
}
|
|
|
|
// GraphsonType implements graphson.Typer interface.
|
|
func (VertexProperty) GraphsonType() graphson.Type {
|
|
return "g:VertexProperty"
|
|
}
|
|
|
|
// String implements fmt.Stringer interface.
|
|
func (vp VertexProperty) String() string {
|
|
return fmt.Sprintf("vp[%s->%v]", vp.Key, vp.Value)
|
|
}
|