mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #8516 from purpleidea/feat/leaseid-okay
clientv3: Allow naked LeaseID or int64 for LeaseValue Compare's
This commit is contained in:
commit
10b731baa8
@ -61,7 +61,7 @@ func Compare(cmp Cmp, result string, v interface{}) Cmp {
|
|||||||
case pb.Compare_MOD:
|
case pb.Compare_MOD:
|
||||||
cmp.TargetUnion = &pb.Compare_ModRevision{ModRevision: mustInt64(v)}
|
cmp.TargetUnion = &pb.Compare_ModRevision{ModRevision: mustInt64(v)}
|
||||||
case pb.Compare_LEASE:
|
case pb.Compare_LEASE:
|
||||||
cmp.TargetUnion = &pb.Compare_Lease{Lease: mustInt64(v)}
|
cmp.TargetUnion = &pb.Compare_Lease{Lease: mustInt64orLeaseID(v)}
|
||||||
default:
|
default:
|
||||||
panic("Unknown compare type")
|
panic("Unknown compare type")
|
||||||
}
|
}
|
||||||
@ -119,6 +119,7 @@ func (cmp Cmp) WithPrefix() Cmp {
|
|||||||
return cmp
|
return cmp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mustInt64 panics if val isn't an int or int64. It returns an int64 otherwise.
|
||||||
func mustInt64(val interface{}) int64 {
|
func mustInt64(val interface{}) int64 {
|
||||||
if v, ok := val.(int64); ok {
|
if v, ok := val.(int64); ok {
|
||||||
return v
|
return v
|
||||||
@ -128,3 +129,12 @@ func mustInt64(val interface{}) int64 {
|
|||||||
}
|
}
|
||||||
panic("bad value")
|
panic("bad value")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mustInt64orLeaseID panics if val isn't a LeaseID, int or int64. It returns an
|
||||||
|
// int64 otherwise.
|
||||||
|
func mustInt64orLeaseID(val interface{}) int64 {
|
||||||
|
if v, ok := val.(LeaseID); ok {
|
||||||
|
return int64(v)
|
||||||
|
}
|
||||||
|
return mustInt64(val)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user