-
Notifications
You must be signed in to change notification settings - Fork 8
/
peer_entity.go
41 lines (33 loc) · 1.07 KB
/
peer_entity.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
package bifrost_entitygraph
import (
"github.com/aperturerobotics/bifrost/peer"
"github.com/aperturerobotics/entitygraph/entity"
)
// PeerEntityTypeName is the entitygraph type name for a Bifrost peer
const PeerEntityTypeName = "bifrost/peer"
// PeerEntity is a entity implementation backed by a node.
type PeerEntity struct {
entityID, entityTypeName string
}
// NewPeerEntityRef constructs a new entity ref to a node.
func NewPeerEntityRef(peerID peer.ID) entity.Ref {
return entity.NewEntityRefWithID(peerID.String(), PeerEntityTypeName)
}
// NewPeerEntity constructs a new PeerEntity.
func NewPeerEntity(peerID peer.ID) *PeerEntity {
nodRef := NewPeerEntityRef(peerID)
nodID := nodRef.GetEntityRefId()
return &PeerEntity{
entityID: nodID,
entityTypeName: PeerEntityTypeName,
}
}
// GetEntityID returns the entity identifier.
func (e *PeerEntity) GetEntityID() string {
return e.entityID
}
// GetEntityTypeName returns the entity type name.
func (e *PeerEntity) GetEntityTypeName() string {
return e.entityTypeName
}
var _ entity.Entity = ((*PeerEntity)(nil))