Update storage to new object format
This commit is contained in:
34
storage/entity/one.go
Normal file
34
storage/entity/one.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package entity
|
||||
|
||||
const (
|
||||
Name = "_id"
|
||||
Relationship = "relationship"
|
||||
Type = "type"
|
||||
Title = "title"
|
||||
Image = "image"
|
||||
Text = "text"
|
||||
Modified = "modified"
|
||||
Connections = "connections"
|
||||
)
|
||||
|
||||
type One struct {
|
||||
Name string `bson:"_id,omitempty"`
|
||||
Type string `bson:"type,omitempty"`
|
||||
Title string `bson:"title,omitempty"`
|
||||
Image string `bson:"image,omitempty"`
|
||||
Text string `bson:"text,omitempty"`
|
||||
Modified int64 `bson:"modified,omitempty"`
|
||||
Connections []Peer `bson:"connections,omitempty"`
|
||||
}
|
||||
|
||||
func (o One) Query() One {
|
||||
return One{Name: o.Name}
|
||||
}
|
||||
|
||||
func (o One) Peers() []string {
|
||||
names := make([]string, len(o.Connections))
|
||||
for i := range o.Connections {
|
||||
names[i] = o.Connections[i].Name
|
||||
}
|
||||
return names
|
||||
}
|
||||
17
storage/entity/one_test.go
Normal file
17
storage/entity/one_test.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOne(t *testing.T) {
|
||||
one := One{
|
||||
Name: "myname",
|
||||
Type: "mytype",
|
||||
}
|
||||
q := one.Query()
|
||||
if want := fmt.Sprint(One{Name: one.Name}); want != fmt.Sprint(q) {
|
||||
t.Error(want, q)
|
||||
}
|
||||
}
|
||||
6
storage/entity/peer.go
Normal file
6
storage/entity/peer.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package entity
|
||||
|
||||
type Peer struct {
|
||||
Name string `bson:"_id,omitempty"`
|
||||
Relationship string `bson:"relationship,omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user