2015-12-19 18:28:08 +00:00
|
|
|
package registry
|
|
|
|
|
|
|
|
import (
|
2018-03-03 11:53:52 +00:00
|
|
|
"context"
|
2016-01-16 23:39:47 +00:00
|
|
|
"crypto/tls"
|
2015-12-19 18:28:08 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Options struct {
|
2016-03-15 22:20:21 +00:00
|
|
|
Addrs []string
|
2016-01-16 23:39:47 +00:00
|
|
|
Timeout time.Duration
|
|
|
|
Secure bool
|
|
|
|
TLSConfig *tls.Config
|
2016-01-06 16:25:12 +00:00
|
|
|
// Other options for implementations of the interface
|
|
|
|
// can be stored in a context
|
|
|
|
Context context.Context
|
2015-12-19 18:28:08 +00:00
|
|
|
}
|
|
|
|
|
2016-01-26 23:32:27 +00:00
|
|
|
type RegisterOptions struct {
|
|
|
|
TTL time.Duration
|
|
|
|
// Other options for implementations of the interface
|
|
|
|
// can be stored in a context
|
|
|
|
Context context.Context
|
2020-06-17 13:23:41 +01:00
|
|
|
// Domain to register the service in
|
|
|
|
Domain string
|
2016-01-26 23:32:27 +00:00
|
|
|
}
|
|
|
|
|
2018-02-19 17:12:37 +00:00
|
|
|
type WatchOptions struct {
|
|
|
|
// Specify a service to watch
|
|
|
|
// If blank, the watch is for all services
|
|
|
|
Service string
|
|
|
|
// Other options for implementations of the interface
|
|
|
|
// can be stored in a context
|
|
|
|
Context context.Context
|
2020-06-17 13:23:41 +01:00
|
|
|
// Domain to watch
|
|
|
|
Domain string
|
2018-02-19 17:12:37 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 12:32:59 +01:00
|
|
|
type DeregisterOptions struct {
|
|
|
|
Context context.Context
|
2020-06-17 13:23:41 +01:00
|
|
|
// Domain the service was registered in
|
|
|
|
Domain string
|
2020-04-14 12:32:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type GetOptions struct {
|
|
|
|
Context context.Context
|
2020-06-17 13:23:41 +01:00
|
|
|
// Domain to scope the request to
|
|
|
|
Domain string
|
2020-04-14 12:32:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type ListOptions struct {
|
|
|
|
Context context.Context
|
2020-06-17 13:23:41 +01:00
|
|
|
// Domain to scope the request to
|
|
|
|
Domain string
|
2020-04-14 12:32:59 +01:00
|
|
|
}
|
|
|
|
|
2016-03-15 22:20:21 +00:00
|
|
|
// Addrs is the registry addresses to use
|
|
|
|
func Addrs(addrs ...string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Addrs = addrs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-19 18:28:08 +00:00
|
|
|
func Timeout(t time.Duration) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Timeout = t
|
|
|
|
}
|
|
|
|
}
|
2016-01-16 20:25:18 +00:00
|
|
|
|
|
|
|
// Secure communication with the registry
|
|
|
|
func Secure(b bool) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Secure = b
|
|
|
|
}
|
|
|
|
}
|
2016-01-16 23:39:47 +00:00
|
|
|
|
|
|
|
// Specify TLS Config
|
|
|
|
func TLSConfig(t *tls.Config) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.TLSConfig = t
|
|
|
|
}
|
|
|
|
}
|
2016-01-26 23:32:27 +00:00
|
|
|
|
2016-01-27 12:23:18 +00:00
|
|
|
func RegisterTTL(t time.Duration) RegisterOption {
|
2016-01-26 23:32:27 +00:00
|
|
|
return func(o *RegisterOptions) {
|
|
|
|
o.TTL = t
|
|
|
|
}
|
|
|
|
}
|
2018-02-19 17:12:37 +00:00
|
|
|
|
2020-04-14 12:32:59 +01:00
|
|
|
func RegisterContext(ctx context.Context) RegisterOption {
|
|
|
|
return func(o *RegisterOptions) {
|
|
|
|
o.Context = ctx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 13:23:41 +01:00
|
|
|
func RegisterDomain(d string) RegisterOption {
|
|
|
|
return func(o *RegisterOptions) {
|
|
|
|
o.Domain = d
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-19 17:12:37 +00:00
|
|
|
// Watch a service
|
|
|
|
func WatchService(name string) WatchOption {
|
|
|
|
return func(o *WatchOptions) {
|
|
|
|
o.Service = name
|
|
|
|
}
|
|
|
|
}
|
2020-04-14 12:32:59 +01:00
|
|
|
|
|
|
|
func WatchContext(ctx context.Context) WatchOption {
|
|
|
|
return func(o *WatchOptions) {
|
|
|
|
o.Context = ctx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 13:23:41 +01:00
|
|
|
func WatchDomain(d string) WatchOption {
|
|
|
|
return func(o *WatchOptions) {
|
|
|
|
o.Domain = d
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-14 12:32:59 +01:00
|
|
|
func DeregisterContext(ctx context.Context) DeregisterOption {
|
|
|
|
return func(o *DeregisterOptions) {
|
|
|
|
o.Context = ctx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 13:23:41 +01:00
|
|
|
func DeregisterDomain(d string) DeregisterOption {
|
|
|
|
return func(o *DeregisterOptions) {
|
|
|
|
o.Domain = d
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-14 12:32:59 +01:00
|
|
|
func GetContext(ctx context.Context) GetOption {
|
|
|
|
return func(o *GetOptions) {
|
|
|
|
o.Context = ctx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 13:23:41 +01:00
|
|
|
func GetDomain(d string) GetOption {
|
|
|
|
return func(o *GetOptions) {
|
|
|
|
o.Domain = d
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-14 12:32:59 +01:00
|
|
|
func ListContext(ctx context.Context) ListOption {
|
|
|
|
return func(o *ListOptions) {
|
|
|
|
o.Context = ctx
|
|
|
|
}
|
|
|
|
}
|
2020-06-17 13:23:41 +01:00
|
|
|
|
|
|
|
func ListDomain(d string) ListOption {
|
|
|
|
return func(o *ListOptions) {
|
|
|
|
o.Domain = d
|
|
|
|
}
|
|
|
|
}
|