fix golint issues in core/discov (#479)

master
Kevin Wan 4 years ago committed by GitHub
parent f6894448bd
commit 2446d8a668
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -14,6 +14,7 @@ const (
const timeToLive int64 = 10 const timeToLive int64 = 10
// TimeToLive is seconds to live in etcd.
var TimeToLive = timeToLive var TimeToLive = timeToLive
func extract(etcdKey string, index int) (string, bool) { func extract(etcdKey string, index int) (string, bool) {

@ -2,11 +2,13 @@ package discov
import "errors" import "errors"
// EtcdConf is the config item with the given key on etcd.
type EtcdConf struct { type EtcdConf struct {
Hosts []string Hosts []string
Key string Key string
} }
// Validate validates c.
func (c EtcdConf) Validate() error { func (c EtcdConf) Validate() error {
if len(c.Hosts) == 0 { if len(c.Hosts) == 0 {
return errors.New("empty etcd hosts") return errors.New("empty etcd hosts")

@ -11,8 +11,10 @@ import (
) )
type ( type (
// PublisherOption defines the method to customize a Publisher.
PublisherOption func(client *Publisher) PublisherOption func(client *Publisher)
// A Publisher can be used to publish the value to an etcd cluster on the given key.
Publisher struct { Publisher struct {
endpoints []string endpoints []string
key 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 { func NewPublisher(endpoints []string, key, value string, opts ...PublisherOption) *Publisher {
publisher := &Publisher{ publisher := &Publisher{
endpoints: endpoints, endpoints: endpoints,
@ -43,6 +49,7 @@ func NewPublisher(endpoints []string, key, value string, opts ...PublisherOption
return publisher return publisher
} }
// KeepAlive keeps key:value alive.
func (p *Publisher) KeepAlive() error { func (p *Publisher) KeepAlive() error {
cli, err := internal.GetRegistry().GetConn(p.endpoints) cli, err := internal.GetRegistry().GetConn(p.endpoints)
if err != nil { if err != nil {
@ -61,14 +68,17 @@ func (p *Publisher) KeepAlive() error {
return p.keepAliveAsync(cli) return p.keepAliveAsync(cli)
} }
// Pause pauses the renewing of key:value.
func (p *Publisher) Pause() { func (p *Publisher) Pause() {
p.pauseChan <- lang.Placeholder p.pauseChan <- lang.Placeholder
} }
// Resume resumes the renewing of key:value.
func (p *Publisher) Resume() { func (p *Publisher) Resume() {
p.resumeChan <- lang.Placeholder p.resumeChan <- lang.Placeholder
} }
// Stop stops the renewing and revokes the registration.
func (p *Publisher) Stop() { func (p *Publisher) Stop() {
p.quit.Close() 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 { func WithId(id int64) PublisherOption {
return func(publisher *Publisher) { return func(publisher *Publisher) {
publisher.id = id publisher.id = id

@ -13,13 +13,19 @@ type (
exclusive bool exclusive bool
} }
// SubOption defines the method to customize a Subscriber.
SubOption func(opts *subOptions) SubOption func(opts *subOptions)
// A Subscriber is used to subscribe the given key on a etcd cluster.
Subscriber struct { Subscriber struct {
items *container 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) { func NewSubscriber(endpoints []string, key string, opts ...SubOption) (*Subscriber, error) {
var subOpts subOptions var subOpts subOptions
for _, opt := range opts { for _, opt := range opts {
@ -36,15 +42,17 @@ func NewSubscriber(endpoints []string, key string, opts ...SubOption) (*Subscrib
return sub, nil return sub, nil
} }
// AddListener adds listener to s.
func (s *Subscriber) AddListener(listener func()) { func (s *Subscriber) AddListener(listener func()) {
s.items.addListener(listener) s.items.addListener(listener)
} }
// Values returns all the subscription values.
func (s *Subscriber) Values() []string { func (s *Subscriber) Values() []string {
return s.items.getValues() 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. // which means later added value will remove the keys associated with the same value previously.
func Exclusive() SubOption { func Exclusive() SubOption {
return func(opts *subOptions) { return func(opts *subOptions) {

Loading…
Cancel
Save