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