opts.go raw

   1  package bunny
   2  
   3  import "net/http"
   4  
   5  // Option is a type for Client options.
   6  type Option func(*Client)
   7  
   8  // WithHTTPRequestLogger is an option to log all sent out HTTP-Request via a log function.
   9  func WithHTTPRequestLogger(logger Logf) Option {
  10  	return func(clt *Client) {
  11  		clt.httpRequestLogf = logger
  12  	}
  13  }
  14  
  15  // WithHTTPResponseLogger is an option to log all received HTTP-Responses via a log function.
  16  func WithHTTPResponseLogger(logger Logf) Option {
  17  	return func(clt *Client) {
  18  		clt.httpResponseLogf = logger
  19  	}
  20  }
  21  
  22  // WithUserAgent is an option to specify the value of the User-Agent HTTP Header.
  23  func WithUserAgent(userAgent string) Option {
  24  	return func(clt *Client) {
  25  		clt.userAgent = userAgent
  26  	}
  27  }
  28  
  29  // WithLogger is an option to set a log function to which informal and warning messages will be logged.
  30  func WithLogger(logger Logf) Option {
  31  	return func(clt *Client) {
  32  		clt.logf = logger
  33  	}
  34  }
  35  
  36  // WithHTTPClient is an option to set the http.Client used by the bunny client.
  37  func WithHTTPClient(client *http.Client) Option {
  38  	return func(clt *Client) {
  39  		if client == nil {
  40  			return
  41  		}
  42  
  43  		clt.httpClient = client
  44  	}
  45  }
  46