aboutsummaryrefslogtreecommitdiffstats
path: root/bug/operation.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-24 20:19:16 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-24 20:19:16 +0200
commita72ea453a919b8f456cc46fbb7a1156d9f649442 (patch)
treefd3b0abae75df2d29184a3b98c681badce8ee4c8 /bug/operation.go
parentc4a207622a894ba9839f1a3c47c9d78beff9b861 (diff)
downloadgit-bug-a72ea453a919b8f456cc46fbb7a1156d9f649442.tar.gz
bug: add the ability to store arbitrary metadata on an operation
Diffstat (limited to 'bug/operation.go')
-rw-r--r--bug/operation.go40
1 files changed, 30 insertions, 10 deletions
diff --git a/bug/operation.go b/bug/operation.go
index b148141c..c57d46d3 100644
--- a/bug/operation.go
+++ b/bug/operation.go
@@ -36,18 +36,23 @@ type Operation interface {
Apply(snapshot Snapshot) Snapshot
// Validate check if the operation is valid (ex: a title is a single line)
Validate() error
+ // SetMetadata store arbitrary metadata about the operation
+ SetMetadata(key string, value string)
+ // GetMetadata retrieve arbitrary metadata about the operation
+ GetMetadata(key string) (string, bool)
}
// OpBase implement the common code for all operations
type OpBase struct {
- OperationType OperationType `json:"type"`
- Author Person `json:"author"`
- UnixTime int64 `json:"timestamp"`
+ OperationType OperationType `json:"type"`
+ Author Person `json:"author"`
+ UnixTime int64 `json:"timestamp"`
+ Metadata map[string]string `json:"metadata,omitempty"`
}
// NewOpBase is the constructor for an OpBase
-func NewOpBase(opType OperationType, author Person) OpBase {
- return OpBase{
+func NewOpBase(opType OperationType, author Person) *OpBase {
+ return &OpBase{
OperationType: opType,
Author: author,
UnixTime: time.Now().Unix(),
@@ -55,27 +60,27 @@ func NewOpBase(opType OperationType, author Person) OpBase {
}
// OpType return the type of operation
-func (op OpBase) OpType() OperationType {
+func (op *OpBase) OpType() OperationType {
return op.OperationType
}
// Time return the time when the operation was added
-func (op OpBase) Time() time.Time {
+func (op *OpBase) Time() time.Time {
return time.Unix(op.UnixTime, 0)
}
// GetUnixTime return the unix timestamp when the operation was added
-func (op OpBase) GetUnixTime() int64 {
+func (op *OpBase) GetUnixTime() int64 {
return op.UnixTime
}
// GetAuthor return the author of the operation
-func (op OpBase) GetAuthor() Person {
+func (op *OpBase) GetAuthor() Person {
return op.Author
}
// GetFiles return the files needed by this operation
-func (op OpBase) GetFiles() []git.Hash {
+func (op *OpBase) GetFiles() []git.Hash {
return nil
}
@@ -101,3 +106,18 @@ func OpBaseValidate(op Operation, opType OperationType) error {
return nil
}
+
+// SetMetadata store arbitrary metadata about the operation
+func (op *OpBase) SetMetadata(key string, value string) {
+ if op.Metadata == nil {
+ op.Metadata = make(map[string]string)
+ }
+
+ op.Metadata[key] = value
+}
+
+// GetMetadata retrieve arbitrary metadata about the operation
+func (op *OpBase) GetMetadata(key string) (string, bool) {
+ val, ok := op.Metadata[key]
+ return val, ok
+}