From 894d79eed32f76cbec2e33f85d9f5521b2ec0a2b Mon Sep 17 00:00:00 2001 From: Aleksandr Zelenin Date: Mon, 24 Dec 2018 00:45:16 +0300 Subject: [PATCH] options fix --- client/client.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/client/client.go b/client/client.go index 1b24931..de8d0b0 100644 --- a/client/client.go +++ b/client/client.go @@ -36,6 +36,12 @@ func WithUpdatesTimeout(timeout time.Duration) Option { } } +func WithProxy(req *AddProxyRequest) Option { + return func(client *Client) { + client.AddProxy(req) + } +} + func NewClient(authorizationStateHandler AuthorizationStateHandler, options ...Option) (*Client, error) { catchersListener := make(chan *Response, 1000) @@ -46,22 +52,14 @@ func NewClient(authorizationStateHandler AuthorizationStateHandler, options ...O catchersStore: &sync.Map{}, } + client.extraGenerator = UuidV4Generator() + client.catchTimeout = 60 * time.Second + client.updatesTimeout = 60 * time.Second + for _, option := range options { option(client) } - if client.extraGenerator == nil { - client.extraGenerator = UuidV4Generator() - } - - if client.catchTimeout == 0 { - client.catchTimeout = 60 * time.Second - } - - if client.updatesTimeout == 0 { - client.updatesTimeout = 60 * time.Second - } - go client.receive() go client.catch(catchersListener)