Browse Source

Allow specifying revision on kvstore methods

main
Sam 5 years ago
parent
commit
c90ef2c03a
  1. 18
      kvstore.go
  2. 6
      types.go

18
kvstore.go

@ -64,7 +64,7 @@ func (kv KV) Keys(namespace string) (KVAPI, error) {
} }
// Get returns an entry // 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{ m := KVAPI{
Params: &kvParams{}, Params: &kvParams{},
} }
@ -74,6 +74,10 @@ func (kv KV) Get(namespace string, key string) (KVAPI, error) {
EntryKey: key, EntryKey: key,
} }
if len(revision) > 0 {
m.Params.Options.Revision = revision[0]
}
m.Method = "get" m.Method = "get"
r, err := kvAPIOut(kv.keybase, m) r, err := kvAPIOut(kv.keybase, m)
@ -84,7 +88,7 @@ func (kv KV) Get(namespace string, key string) (KVAPI, error) {
} }
// Put adds an entry // 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{ m := KVAPI{
Params: &kvParams{}, Params: &kvParams{},
} }
@ -95,6 +99,10 @@ func (kv KV) Put(namespace string, key string, value string) (KVAPI, error) {
EntryValue: value, EntryValue: value,
} }
if len(revision) > 0 {
m.Params.Options.Revision = revision[0]
}
m.Method = "put" m.Method = "put"
r, err := kvAPIOut(kv.keybase, m) 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 // 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{ m := KVAPI{
Params: &kvParams{}, Params: &kvParams{},
} }
@ -115,6 +123,10 @@ func (kv KV) Delete(namespace string, key string) (KVAPI, error) {
EntryKey: key, EntryKey: key,
} }
if len(revision) > 0 {
m.Params.Options.Revision = revision[0]
}
m.Method = "del" m.Method = "del"
r, err := kvAPIOut(kv.keybase, m) r, err := kvAPIOut(kv.keybase, m)

6
types.go

@ -659,7 +659,7 @@ type kvOptions struct {
Team string `json:"team,omitempty"` Team string `json:"team,omitempty"`
Namespace string `json:"namespace,omitempty"` Namespace string `json:"namespace,omitempty"`
EntryKey string `json:"entryKey,omitempty"` EntryKey string `json:"entryKey,omitempty"`
Revision int `json:"revision,omitempty"` Revision uint `json:"revision,omitempty"`
EntryValue string `json:"entryValue,omitempty"` EntryValue string `json:"entryValue,omitempty"`
} }
@ -669,7 +669,7 @@ type kvParams struct {
type entryKey struct { type entryKey struct {
EntryKey string `json:"entryKey"` EntryKey string `json:"entryKey"`
Revision int `json:"revision"` Revision uint `json:"revision"`
} }
type kvResult struct { type kvResult struct {
@ -678,7 +678,7 @@ type kvResult struct {
EntryKeys []entryKey `json:"entryKeys"` EntryKeys []entryKey `json:"entryKeys"`
EntryKey string `json:"entryKey"` EntryKey string `json:"entryKey"`
EntryValue string `json:"entryValue"` EntryValue string `json:"entryValue"`
Revision int `json:"revision"` Revision uint `json:"revision"`
} }
// UserAPI holds information received from the user/lookup api // UserAPI holds information received from the user/lookup api

Loading…
Cancel
Save