aboutsummaryrefslogtreecommitdiffstats
path: root/identity/version.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-01-17 02:05:50 +0100
committerMichael Muré <batolettre@gmail.com>2019-03-01 22:35:37 +0100
commit3df4f46c71650c9d23b267c44afec16f1b759e92 (patch)
tree516540f3cd71acc0c000f1bdc2a9a9252501dacd /identity/version.go
parent06d9c6872655b85f1a47599add92d49d570e7b2e (diff)
downloadgit-bug-3df4f46c71650c9d23b267c44afec16f1b759e92.tar.gz
identity: add metadata support
Diffstat (limited to 'identity/version.go')
-rw-r--r--identity/version.go26
1 files changed, 25 insertions, 1 deletions
diff --git a/identity/version.go b/identity/version.go
index 3e84ece3..bc4561d9 100644
--- a/identity/version.go
+++ b/identity/version.go
@@ -12,7 +12,7 @@ import (
"github.com/MichaelMure/git-bug/util/text"
)
-// Version is a complete set of informations about an Identity at a point in time.
+// Version is a complete set of information about an Identity at a point in time.
type Version struct {
// Private field so not serialized
commitHash git.Hash
@@ -35,6 +35,9 @@ type Version struct {
// It has no functional purpose and should be ignored.
// It is advised to fill this array if there is not enough entropy, e.g. if there is no keys.
Nonce []byte `json:"nonce,omitempty"`
+
+ // A set of arbitrary key/value to store metadata about a version or about an Identity in general.
+ Metadata map[string]string `json:"metadata,omitempty"`
}
func (v *Version) Validate() error {
@@ -103,3 +106,24 @@ func makeNonce(len int) []byte {
}
return result
}
+
+// SetMetadata store arbitrary metadata about a version or an Identity in general
+// If the Version has been commit to git already, it won't be overwritten.
+func (v *Version) SetMetadata(key string, value string) {
+ if v.Metadata == nil {
+ v.Metadata = make(map[string]string)
+ }
+
+ v.Metadata[key] = value
+}
+
+// GetMetadata retrieve arbitrary metadata about the Version
+func (v *Version) GetMetadata(key string) (string, bool) {
+ val, ok := v.Metadata[key]
+ return val, ok
+}
+
+// AllMetadata return all metadata for this Identity
+func (v *Version) AllMetadata() map[string]string {
+ return v.Metadata
+}