operation.go

 1package bug
 2
 3import "time"
 4
 5type OperationType int
 6
 7const (
 8	_ OperationType = iota
 9	CreateOp
10	SetTitleOp
11	AddCommentOp
12	SetStatusOp
13	LabelChangeOp
14)
15
16type Operation interface {
17	OpType() OperationType
18	Time() time.Time
19	Apply(snapshot Snapshot) Snapshot
20}
21
22type OpBase struct {
23	OperationType OperationType
24	Author        Person
25	UnixTime      int64
26}
27
28func NewOpBase(opType OperationType, author Person) OpBase {
29	return OpBase{
30		OperationType: opType,
31		Author:        author,
32		UnixTime:      time.Now().Unix(),
33	}
34}
35
36func (op OpBase) OpType() OperationType {
37	return op.OperationType
38}
39
40func (op OpBase) Time() time.Time {
41	return time.Unix(op.UnixTime, 0)
42}