add registry helpers

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-11-05 21:17:40 +03:00
parent 1fbf8b2e20
commit e127547799

View File

@ -41,6 +41,17 @@ type RegisterOptions struct {
Attempts int Attempts int
} }
func NewRegisterOptions(opts ...RegisterOption) RegisterOptions {
options := RegisterOptions{
Domain: DefaultDomain,
Context: context.Background(),
}
for _, o := range opts {
o(&options)
}
return options
}
type WatchOptions struct { type WatchOptions struct {
// Specify a service to watch // Specify a service to watch
// If blank, the watch is for all services // If blank, the watch is for all services
@ -52,6 +63,17 @@ type WatchOptions struct {
Domain string Domain string
} }
func NewWatchOptions(opts ...WatchOption) WatchOptions {
options := WatchOptions{
Domain: DefaultDomain,
Context: context.Background(),
}
for _, o := range opts {
o(&options)
}
return options
}
type DeregisterOptions struct { type DeregisterOptions struct {
Context context.Context Context context.Context
// Domain the service was registered in // Domain the service was registered in
@ -60,18 +82,51 @@ type DeregisterOptions struct {
Attempts int Attempts int
} }
func NewDeregisterOptions(opts ...DeregisterOption) DeregisterOptions {
options := DeregisterOptions{
Domain: DefaultDomain,
Context: context.Background(),
}
for _, o := range opts {
o(&options)
}
return options
}
type GetOptions struct { type GetOptions struct {
Context context.Context Context context.Context
// Domain to scope the request to // Domain to scope the request to
Domain string Domain string
} }
func NewGetOptions(opts ...GetOption) GetOptions {
options := GetOptions{
Domain: DefaultDomain,
Context: context.Background(),
}
for _, o := range opts {
o(&options)
}
return options
}
type ListOptions struct { type ListOptions struct {
Context context.Context Context context.Context
// Domain to scope the request to // Domain to scope the request to
Domain string Domain string
} }
func NewListOptions(opts ...ListOption) ListOptions {
options := ListOptions{
Domain: DefaultDomain,
Context: context.Background(),
}
for _, o := range opts {
o(&options)
}
return options
}
// Addrs is the registry addresses to use // Addrs is the registry addresses to use
func Addrs(addrs ...string) Option { func Addrs(addrs ...string) Option {
return func(o *Options) { return func(o *Options) {