From c90ef2c03a13dac520fd6d3a36c4dfe8048e9c76 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 23 Jan 2020 16:49:12 -0500 Subject: [PATCH] Allow specifying revision on kvstore methods --- kvstore.go | 18 +++++++++++++++--- types.go | 6 +++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/kvstore.go b/kvstore.go index 4764a51..ac91b25 100644 --- a/kvstore.go +++ b/kvstore.go @@ -64,7 +64,7 @@ func (kv KV) Keys(namespace string) (KVAPI, error) { } // Get returns an entry -func (kv KV) Get(namespace string, key string) (KVAPI, error) { +func (kv KV) Get(namespace string, key string, revision ...uint) (KVAPI, error) { m := KVAPI{ Params: &kvParams{}, } @@ -74,6 +74,10 @@ func (kv KV) Get(namespace string, key string) (KVAPI, error) { EntryKey: key, } + if len(revision) > 0 { + m.Params.Options.Revision = revision[0] + } + m.Method = "get" r, err := kvAPIOut(kv.keybase, m) @@ -84,7 +88,7 @@ func (kv KV) Get(namespace string, key string) (KVAPI, error) { } // Put adds an entry -func (kv KV) Put(namespace string, key string, value string) (KVAPI, error) { +func (kv KV) Put(namespace string, key string, value string, revision ...uint) (KVAPI, error) { m := KVAPI{ Params: &kvParams{}, } @@ -95,6 +99,10 @@ func (kv KV) Put(namespace string, key string, value string) (KVAPI, error) { EntryValue: value, } + if len(revision) > 0 { + m.Params.Options.Revision = revision[0] + } + m.Method = "put" r, err := kvAPIOut(kv.keybase, m) @@ -105,7 +113,7 @@ func (kv KV) Put(namespace string, key string, value string) (KVAPI, error) { } // Delete removes an entry -func (kv KV) Delete(namespace string, key string) (KVAPI, error) { +func (kv KV) Delete(namespace string, key string, revision ...uint) (KVAPI, error) { m := KVAPI{ Params: &kvParams{}, } @@ -115,6 +123,10 @@ func (kv KV) Delete(namespace string, key string) (KVAPI, error) { EntryKey: key, } + if len(revision) > 0 { + m.Params.Options.Revision = revision[0] + } + m.Method = "del" r, err := kvAPIOut(kv.keybase, m) diff --git a/types.go b/types.go index 06e8fa4..7a10120 100644 --- a/types.go +++ b/types.go @@ -659,7 +659,7 @@ type kvOptions struct { Team string `json:"team,omitempty"` Namespace string `json:"namespace,omitempty"` EntryKey string `json:"entryKey,omitempty"` - Revision int `json:"revision,omitempty"` + Revision uint `json:"revision,omitempty"` EntryValue string `json:"entryValue,omitempty"` } @@ -669,7 +669,7 @@ type kvParams struct { type entryKey struct { EntryKey string `json:"entryKey"` - Revision int `json:"revision"` + Revision uint `json:"revision"` } type kvResult struct { @@ -678,7 +678,7 @@ type kvResult struct { EntryKeys []entryKey `json:"entryKeys"` EntryKey string `json:"entryKey"` EntryValue string `json:"entryValue"` - Revision int `json:"revision"` + Revision uint `json:"revision"` } // UserAPI holds information received from the user/lookup api