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