Compare commits
3 Commits
feature/ap
...
34c9f035ee
Author | SHA1 | Date | |
---|---|---|---|
34c9f035ee | |||
628eac60b4 | |||
840ca01f87 |
4
go.mod
4
go.mod
@ -4,8 +4,6 @@ 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 (
|
||||||
@ -13,7 +11,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.5
|
github.com/gin-gonic/gin v1.7.6
|
||||||
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,14 +11,16 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.etcd.io/etcd/clientv3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WatchKey 监听key的变化,永久监听
|
// WatchKeyWithOption ...
|
||||||
//
|
//
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 2:58 下午 2021/11/23
|
// Date : 2:29 下午 2021/11/26
|
||||||
func WatchKey(ctx context.Context, watchKey string, callbackFunc WatcherHandler) {
|
func WatchKeyWithOption(ctx context.Context, watchKey string, callbackFunc WatcherHandler, optionList ...clientv3.OpOption) {
|
||||||
if nil == callbackFunc {
|
if nil == callbackFunc {
|
||||||
// 变化之后,没有任何逻辑处理,视为不需要监听变化
|
// 变化之后,没有任何逻辑处理,视为不需要监听变化
|
||||||
return
|
return
|
||||||
@ -27,7 +29,7 @@ func WatchKey(ctx context.Context, watchKey string, callbackFunc WatcherHandler)
|
|||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
}
|
}
|
||||||
|
|
||||||
rch := Client.Watch(ctx, watchKey) // <-chan WatchResponse
|
rch := Client.Watch(ctx, watchKey, optionList...) // <-chan WatchResponse
|
||||||
for watchResp := range rch {
|
for watchResp := range rch {
|
||||||
for _, ev := range watchResp.Events {
|
for _, ev := range watchResp.Events {
|
||||||
callbackFunc(ev)
|
callbackFunc(ev)
|
||||||
@ -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 可以随时取消的
|
// WatchKeyWithCancel 可以随时取消的
|
||||||
//
|
//
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
Reference in New Issue
Block a user