From 2446d8a668a2af9d4d7464fa83519f878de53835 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Thu, 18 Feb 2021 22:56:35 +0800 Subject: [PATCH] fix golint issues in core/discov (#479) --- core/discov/clients.go | 1 + core/discov/config.go | 2 ++ core/discov/publisher.go | 11 +++++++++++ core/discov/subscriber.go | 10 +++++++++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/core/discov/clients.go b/core/discov/clients.go index c97555da..229abdcc 100644 --- a/core/discov/clients.go +++ b/core/discov/clients.go @@ -14,6 +14,7 @@ const ( const timeToLive int64 = 10 +// TimeToLive is seconds to live in etcd. var TimeToLive = timeToLive func extract(etcdKey string, index int) (string, bool) { diff --git a/core/discov/config.go b/core/discov/config.go index e9da8d10..c4dd53ca 100644 --- a/core/discov/config.go +++ b/core/discov/config.go @@ -2,11 +2,13 @@ package discov import "errors" +// EtcdConf is the config item with the given key on etcd. type EtcdConf struct { Hosts []string Key string } +// Validate validates c. func (c EtcdConf) Validate() error { if len(c.Hosts) == 0 { return errors.New("empty etcd hosts") diff --git a/core/discov/publisher.go b/core/discov/publisher.go index 4b4609db..873cbc32 100644 --- a/core/discov/publisher.go +++ b/core/discov/publisher.go @@ -11,8 +11,10 @@ import ( ) type ( + // PublisherOption defines the method to customize a Publisher. PublisherOption func(client *Publisher) + // A Publisher can be used to publish the value to an etcd cluster on the given key. Publisher struct { endpoints []string key string @@ -26,6 +28,10 @@ type ( } ) +// NewPublisher returns a Publisher. +// endpoints is the hosts of the etcd cluster. +// key:value are a pair to be published. +// opts are used to customize the Publisher. func NewPublisher(endpoints []string, key, value string, opts ...PublisherOption) *Publisher { publisher := &Publisher{ endpoints: endpoints, @@ -43,6 +49,7 @@ func NewPublisher(endpoints []string, key, value string, opts ...PublisherOption return publisher } +// KeepAlive keeps key:value alive. func (p *Publisher) KeepAlive() error { cli, err := internal.GetRegistry().GetConn(p.endpoints) if err != nil { @@ -61,14 +68,17 @@ func (p *Publisher) KeepAlive() error { return p.keepAliveAsync(cli) } +// Pause pauses the renewing of key:value. func (p *Publisher) Pause() { p.pauseChan <- lang.Placeholder } +// Resume resumes the renewing of key:value. func (p *Publisher) Resume() { p.resumeChan <- lang.Placeholder } +// Stop stops the renewing and revokes the registration. func (p *Publisher) Stop() { p.quit.Close() } @@ -135,6 +145,7 @@ func (p *Publisher) revoke(cli internal.EtcdClient) { } } +// WithId customizes a Publisher with the id. func WithId(id int64) PublisherOption { return func(publisher *Publisher) { publisher.id = id diff --git a/core/discov/subscriber.go b/core/discov/subscriber.go index 94c81bfc..83c97fcb 100644 --- a/core/discov/subscriber.go +++ b/core/discov/subscriber.go @@ -13,13 +13,19 @@ type ( exclusive bool } + // SubOption defines the method to customize a Subscriber. SubOption func(opts *subOptions) + // A Subscriber is used to subscribe the given key on a etcd cluster. Subscriber struct { items *container } ) +// NewSubscriber returns a Subscriber. +// endpoints is the hosts of the etcd cluster. +// 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 { @@ -36,15 +42,17 @@ func NewSubscriber(endpoints []string, key string, opts ...SubOption) (*Subscrib return sub, nil } +// AddListener adds listener to s. func (s *Subscriber) AddListener(listener func()) { s.items.addListener(listener) } +// Values returns all the subscription values. func (s *Subscriber) Values() []string { return s.items.getValues() } -// exclusive means that key value can only be 1:1, +// 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) {