Compare commits
0
Commits
No files matched your search
@@ -4,6 +4,8 @@ go 1.17
|
|||||||
|
|
||||||
replace github.com/coreos/bbolt v1.3.4 => go.etcd.io/bbolt v1.3.4
|
replace github.com/coreos/bbolt v1.3.4 => go.etcd.io/bbolt v1.3.4
|
||||||
|
|
||||||
|
replace github.com/gin-gonic/gin v1.7.5 => github.com/gin-gonic/gin v1.7.6
|
||||||
|
|
||||||
replace google.golang.org/grpc => google.golang.org/grpc v1.26.0
|
replace google.golang.org/grpc => google.golang.org/grpc v1.26.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@@ -11,7 +13,7 @@ require (
|
|||||||
github.com/apolloconfig/agollo/v4 v4.0.9
|
github.com/apolloconfig/agollo/v4 v4.0.9
|
||||||
github.com/coreos/etcd v3.3.27+incompatible
|
github.com/coreos/etcd v3.3.27+incompatible
|
||||||
github.com/ddliu/go-httpclient v0.6.9
|
github.com/ddliu/go-httpclient v0.6.9
|
||||||
github.com/gin-gonic/gin v1.7.6
|
github.com/gin-gonic/gin v1.7.5
|
||||||
github.com/go-redis/redis/v8 v8.11.4
|
github.com/go-redis/redis/v8 v8.11.4
|
||||||
github.com/go-redis/redis_rate/v9 v9.1.2
|
github.com/go-redis/redis_rate/v9 v9.1.2
|
||||||
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
|
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
|
||||||
|
|||||||
@@ -11,16 +11,14 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.etcd.io/etcd/clientv3"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// WatchKeyWithOption ...
|
// WatchKey 监听key的变化,永久监听
|
||||||
//
|
//
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 2:29 下午 2021/11/26
|
// Date : 2:58 下午 2021/11/23
|
||||||
func WatchKeyWithOption(ctx context.Context, watchKey string, callbackFunc WatcherHandler, optionList ...clientv3.OpOption) {
|
func WatchKey(ctx context.Context, watchKey string, callbackFunc WatcherHandler) {
|
||||||
if nil == callbackFunc {
|
if nil == callbackFunc {
|
||||||
// 变化之后,没有任何逻辑处理,视为不需要监听变化
|
// 变化之后,没有任何逻辑处理,视为不需要监听变化
|
||||||
return
|
return
|
||||||
@@ -29,7 +27,7 @@ func WatchKeyWithOption(ctx context.Context, watchKey string, callbackFunc Watch
|
|||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
}
|
}
|
||||||
|
|
||||||
rch := Client.Watch(ctx, watchKey, optionList...) // <-chan WatchResponse
|
rch := Client.Watch(ctx, watchKey) // <-chan WatchResponse
|
||||||
for watchResp := range rch {
|
for watchResp := range rch {
|
||||||
for _, ev := range watchResp.Events {
|
for _, ev := range watchResp.Events {
|
||||||
callbackFunc(ev)
|
callbackFunc(ev)
|
||||||
@@ -37,24 +35,6 @@ func WatchKeyWithOption(ctx context.Context, watchKey string, callbackFunc Watch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 可以随时取消的
|
// WatchKeyWithCancel 可以随时取消的
|
||||||
//
|
//
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
|||||||