feat: added configuration center function (#3035)

Co-authored-by: aiden.ma <Aiden.ma@yijinin.com>
This commit is contained in:
MarkJoyMa
2024-08-28 14:47:52 +08:00
committed by GitHub
parent 47d13e5ef8
commit 44cddec5c3
9 changed files with 628 additions and 25 deletions

View File

@@ -15,9 +15,10 @@ type (
// A Subscriber is used to subscribe the given key on an etcd cluster.
Subscriber struct {
endpoints []string
exclusive bool
items *container
endpoints []string
exclusive bool
disablePrefix bool
items *container
}
)
@@ -34,7 +35,7 @@ func NewSubscriber(endpoints []string, key string, opts ...SubOption) (*Subscrib
}
sub.items = newContainer(sub.exclusive)
if err := internal.GetRegistry().Monitor(endpoints, key, sub.items); err != nil {
if err := internal.GetRegistry().Monitor(endpoints, key, sub.items, sub.disablePrefix); err != nil {
return nil, err
}
@@ -59,6 +60,13 @@ func Exclusive() SubOption {
}
}
// WithDisablePrefix turn off querying using key prefixes.
func WithDisablePrefix() SubOption {
return func(sub *Subscriber) {
sub.disablePrefix = true
}
}
// WithSubEtcdAccount provides the etcd username/password.
func WithSubEtcdAccount(user, pass string) SubOption {
return func(sub *Subscriber) {