-
Notifications
You must be signed in to change notification settings - Fork 0
/
vertex.go
62 lines (51 loc) · 1.45 KB
/
vertex.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2019-present Facebook Inc. All rights reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
package graph
import (
"fmt"
"github.com/storskegg/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)
}