client: support PrevIndex in SetOptions & DeleteOptions
parent
7ccf5eb476
commit
bc32060b1d
|
@ -76,11 +76,13 @@ type KeysAPI interface {
|
||||||
|
|
||||||
type SetOptions struct {
|
type SetOptions struct {
|
||||||
PrevValue string
|
PrevValue string
|
||||||
|
PrevIndex uint64
|
||||||
PrevExist PrevExistType
|
PrevExist PrevExistType
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeleteOptions struct {
|
type DeleteOptions struct {
|
||||||
PrevValue string
|
PrevValue string
|
||||||
|
PrevIndex uint64
|
||||||
Recursive bool
|
Recursive bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,6 +289,9 @@ func (a *setAction) HTTPRequest(ep url.URL) *http.Request {
|
||||||
if a.Options.PrevValue != "" {
|
if a.Options.PrevValue != "" {
|
||||||
params.Set("prevValue", a.Options.PrevValue)
|
params.Set("prevValue", a.Options.PrevValue)
|
||||||
}
|
}
|
||||||
|
if a.Options.PrevIndex != 0 {
|
||||||
|
params.Set("prevIndex", strconv.FormatUint(a.Options.PrevIndex, 10))
|
||||||
|
}
|
||||||
if a.Options.PrevExist != PrevIgnore {
|
if a.Options.PrevExist != PrevIgnore {
|
||||||
params.Set("prevExist", string(a.Options.PrevExist))
|
params.Set("prevExist", string(a.Options.PrevExist))
|
||||||
}
|
}
|
||||||
|
@ -316,6 +321,9 @@ func (a *deleteAction) HTTPRequest(ep url.URL) *http.Request {
|
||||||
if a.Options.PrevValue != "" {
|
if a.Options.PrevValue != "" {
|
||||||
params.Set("prevValue", a.Options.PrevValue)
|
params.Set("prevValue", a.Options.PrevValue)
|
||||||
}
|
}
|
||||||
|
if a.Options.PrevIndex != 0 {
|
||||||
|
params.Set("prevIndex", strconv.FormatUint(a.Options.PrevIndex, 10))
|
||||||
|
}
|
||||||
if a.Options.Recursive {
|
if a.Options.Recursive {
|
||||||
params.Set("recursive", "true")
|
params.Set("recursive", "true")
|
||||||
}
|
}
|
||||||
|
|
|
@ -301,6 +301,18 @@ func TestSetAction(t *testing.T) {
|
||||||
wantURL: "http://example.com/foo?prevValue=bar+baz",
|
wantURL: "http://example.com/foo?prevValue=bar+baz",
|
||||||
wantBody: "value=",
|
wantBody: "value=",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// PrevIndex is set
|
||||||
|
{
|
||||||
|
act: setAction{
|
||||||
|
Key: "foo",
|
||||||
|
Options: SetOptions{
|
||||||
|
PrevIndex: uint64(12),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantURL: "http://example.com/foo?prevIndex=12",
|
||||||
|
wantBody: "value=",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
|
@ -398,6 +410,17 @@ func TestDeleteAction(t *testing.T) {
|
||||||
},
|
},
|
||||||
wantURL: "http://example.com/foo?prevValue=bar+baz",
|
wantURL: "http://example.com/foo?prevValue=bar+baz",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// PrevIndex is set
|
||||||
|
{
|
||||||
|
act: deleteAction{
|
||||||
|
Key: "foo",
|
||||||
|
Options: DeleteOptions{
|
||||||
|
PrevIndex: uint64(12),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantURL: "http://example.com/foo?prevIndex=12",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
|
|
Loading…
Reference in New Issue