Allow specifying revision on kvstore methods

This commit is contained in:
Sam
2020-01-23 16:49:12 -05:00
parent b83a1e0227
commit c90ef2c03a
2 changed files with 18 additions and 6 deletions

View File

@ -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)

View File

@ -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