fix golint issues in core/discov (#479)

This commit is contained in:
Kevin Wan
2021-02-18 22:56:35 +08:00
committed by GitHub
parent f6894448bd
commit 2446d8a668
4 changed files with 23 additions and 1 deletions

View File

@@ -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