From e12754779912ed7711054a7ad0f84b2fecbab248 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 5 Nov 2020 21:17:40 +0300 Subject: [PATCH] add registry helpers Signed-off-by: Vasiliy Tolstov --- registry/options.go | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/registry/options.go b/registry/options.go index 0134cfbd..08f37c86 100644 --- a/registry/options.go +++ b/registry/options.go @@ -41,6 +41,17 @@ type RegisterOptions struct { 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 { // Specify a service to watch // If blank, the watch is for all services @@ -52,6 +63,17 @@ type WatchOptions struct { 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 { Context context.Context // Domain the service was registered in @@ -60,18 +82,51 @@ type DeregisterOptions struct { 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 { Context context.Context // Domain to scope the request to 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 { Context context.Context // Domain to scope the request to 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 func Addrs(addrs ...string) Option { return func(o *Options) {