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<白茶清欢>