From 628eac60b4c295da56c65a9542901d715a892461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 26 Nov 2021 14:31:25 +0800 Subject: [PATCH] add watch key with prefix --- middleware/etcd/watch.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/middleware/etcd/watch.go b/middleware/etcd/watch.go index 9340e75..e080d55 100644 --- a/middleware/etcd/watch.go +++ b/middleware/etcd/watch.go @@ -11,14 +11,16 @@ import ( "context" "math" "time" + + "go.etcd.io/etcd/clientv3" ) -// WatchKey 监听key的变化,永久监听 +// WatchKeyWithOption ... // // Author : go_developer@163.com<白茶清欢> // -// Date : 2:58 下午 2021/11/23 -func WatchKey(ctx context.Context, watchKey string, callbackFunc WatcherHandler) { +// Date : 2:29 下午 2021/11/26 +func WatchKeyWithOption(ctx context.Context, watchKey string, callbackFunc WatcherHandler, optionList ...clientv3.OpOption) { if nil == callbackFunc { // 变化之后,没有任何逻辑处理,视为不需要监听变化 return @@ -35,6 +37,24 @@ func WatchKey(ctx context.Context, watchKey string, callbackFunc WatcherHandler) } } +// WatchKey 监听key的变化,永久监听 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2:58 下午 2021/11/23 +func WatchKey(ctx context.Context, watchKey string, callbackFunc WatcherHandler) { + WatchKeyWithOption(ctx, watchKey, callbackFunc) +} + +// WatchWithKeyPrefix ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2:30 下午 2021/11/26 +func WatchWithKeyPrefix(ctx context.Context, watchKey string, callbackFunc WatcherHandler) { + WatchKeyWithOption(ctx, watchKey, callbackFunc, clientv3.WithPrefix()) +} + // WatchKeyWithCancel 可以随时取消的 // // Author : go_developer@163.com<白茶清欢>