option.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. package lanz
  5. import "time"
  6. // Option is a LANZ client factory option.
  7. type Option func(c *client)
  8. // WithAddr specifies the address of the LANZ server.
  9. // If WithConnector is not used, then WithAddr must be used.
  10. // When WithConnector is used, WithAddr can be used to pass the address string for displaying.
  11. func WithAddr(addr string) Option {
  12. return func(c *client) {
  13. c.addr = addr
  14. }
  15. }
  16. // WithConnector specifies a connector used to communicate with LANZ server.
  17. func WithConnector(conn ConnectReadCloser) Option {
  18. return func(c *client) {
  19. c.conn = conn
  20. }
  21. }
  22. // WithTimeout specifies the timeout for connecting to LANZ server.
  23. // It only takes effect for default connector.
  24. func WithTimeout(d time.Duration) Option {
  25. return func(c *client) {
  26. c.timeout = d
  27. }
  28. }
  29. // WithBackoff specifies the backoff time after failed connection to LANZ server.
  30. // It only takes effect for default connector.
  31. func WithBackoff(d time.Duration) Option {
  32. return func(c *client) {
  33. c.backoff = d
  34. }
  35. }