github.com/aristanetworks/goarista@v0.0.0-20240514173732-cca2755bbd44/lanz/option.go (about) 1 // Copyright (c) 2016 Arista Networks, Inc. 2 // Use of this source code is governed by the Apache License 2.0 3 // that can be found in the COPYING file. 4 5 package lanz 6 7 import ( 8 "time" 9 10 "github.com/aristanetworks/goarista/logger" 11 ) 12 13 // Option is a LANZ client factory option. 14 type Option func(c *client) 15 16 // WithAddr specifies the address of the LANZ server. 17 // If WithConnector is not used, then WithAddr must be used. 18 // When WithConnector is used, WithAddr can be used to pass the address string for displaying. 19 func WithAddr(addr string) Option { 20 return func(c *client) { 21 c.addr = addr 22 } 23 } 24 25 // WithConnector specifies a connector used to communicate with LANZ server. 26 func WithConnector(conn ConnectReadCloser) Option { 27 return func(c *client) { 28 c.conn = conn 29 } 30 } 31 32 // WithTimeout specifies the timeout for connecting to LANZ server. 33 // It only takes effect for default connector. 34 func WithTimeout(d time.Duration) Option { 35 return func(c *client) { 36 c.timeout = d 37 } 38 } 39 40 // WithBackoff specifies the backoff time after failed connection to LANZ server. 41 // It only takes effect for default connector. 42 func WithBackoff(d time.Duration) Option { 43 return func(c *client) { 44 c.backoff = d 45 } 46 } 47 48 // WithLogger sets the logger to be used by this lanz client. 49 func WithLogger(l logger.Logger) Option { 50 return func(c *client) { 51 c.log = l 52 } 53 }