feat: support auth account for etcd (#1174)
This commit is contained in:
@@ -9,16 +9,14 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
subOptions struct {
|
||||
exclusive bool
|
||||
}
|
||||
|
||||
// SubOption defines the method to customize a Subscriber.
|
||||
SubOption func(opts *subOptions)
|
||||
SubOption func(sub *Subscriber)
|
||||
|
||||
// A Subscriber is used to subscribe the given key on a etcd cluster.
|
||||
Subscriber struct {
|
||||
items *container
|
||||
endpoints []string
|
||||
exclusive bool
|
||||
items *container
|
||||
}
|
||||
)
|
||||
|
||||
@@ -27,14 +25,14 @@ type (
|
||||
// key is the key to subscribe.
|
||||
// opts are used to customize the Subscriber.
|
||||
func NewSubscriber(endpoints []string, key string, opts ...SubOption) (*Subscriber, error) {
|
||||
var subOpts subOptions
|
||||
for _, opt := range opts {
|
||||
opt(&subOpts)
|
||||
}
|
||||
|
||||
sub := &Subscriber{
|
||||
items: newContainer(subOpts.exclusive),
|
||||
endpoints: endpoints,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(sub)
|
||||
}
|
||||
sub.items = newContainer(sub.exclusive)
|
||||
|
||||
if err := internal.GetRegistry().Monitor(endpoints, key, sub.items); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -55,8 +53,14 @@ func (s *Subscriber) Values() []string {
|
||||
// Exclusive means that key value can only be 1:1,
|
||||
// which means later added value will remove the keys associated with the same value previously.
|
||||
func Exclusive() SubOption {
|
||||
return func(opts *subOptions) {
|
||||
opts.exclusive = true
|
||||
return func(sub *Subscriber) {
|
||||
sub.exclusive = true
|
||||
}
|
||||
}
|
||||
|
||||
func WithSubEtcdAccount(user, pass string) SubOption {
|
||||
return func(sub *Subscriber) {
|
||||
internal.AddAccount(sub.endpoints, user, pass)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user