From 88a9cf2cea780720d2bf0034a8fb1bb89fcd71bf Mon Sep 17 00:00:00 2001 From: westhood Date: Thu, 7 Jul 2016 10:35:40 +0800 Subject: [PATCH] clientv3: add public function to get prefix range end --- clientv3/op.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/clientv3/op.go b/clientv3/op.go index 58e2c94cc..2fc803cbb 100644 --- a/clientv3/op.go +++ b/clientv3/op.go @@ -184,6 +184,12 @@ func WithSort(target SortTarget, order SortOrder) OpOption { } } +// GetPrefixRangeEnd gets the range end of the prefix. +// 'Get(foo, WithPrefix())' is equal to 'Get(foo, WithRange(GetPrefixRangeEnd(foo))'. +func GetPrefixRangeEnd(prefix string) string { + return string(getPrefix([]byte(prefix))) +} + func getPrefix(key []byte) []byte { end := make([]byte, len(key)) copy(end, key)