-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathconsensus.go
More file actions
45 lines (38 loc) · 819 Bytes
/
consensus.go
File metadata and controls
45 lines (38 loc) · 819 Bytes
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
package consensus
import (
"strings"
"time"
)
type Log struct {
Id string `bson:"_id"`
Records []Record `bson:"records"`
Err error `bson:"-"`
}
type Record struct {
Id string `bson:"id"`
PrevId string `bson:"prevId"`
Payload []byte `bson:"payload,omitempty"`
Created time.Time `bson:"created"`
}
func NewPayload(logId, recordId string, payload []byte) Payload {
return Payload{
Id: logId + "/" + recordId,
Payload: payload,
}
}
type Payload struct {
Id string `bson:"_id"`
Payload []byte `bson:"payload"`
}
func (p Payload) RecordId() string {
if idx := strings.LastIndex(p.Id, "/"); idx >= 0 {
return p.Id[idx+1:]
}
return ""
}
func (p Payload) LogId() string {
if idx := strings.LastIndex(p.Id, "/"); idx >= 0 {
return p.Id[:idx]
}
return ""
}