Scott Baker | 8487c5d | 2019-10-18 12:49:46 -0700 | [diff] [blame] | 1 | package client |
| 2 | |
| 3 | import "log" |
| 4 | |
| 5 | // Settings holds optional client settings. |
| 6 | type Settings struct { |
| 7 | disablePAFXFast bool |
| 8 | assumePreAuthentication bool |
| 9 | preAuthEType int32 |
| 10 | logger *log.Logger |
| 11 | } |
| 12 | |
| 13 | // NewSettings creates a new client settings struct. |
| 14 | func NewSettings(settings ...func(*Settings)) *Settings { |
| 15 | s := new(Settings) |
| 16 | for _, set := range settings { |
| 17 | set(s) |
| 18 | } |
| 19 | return s |
| 20 | } |
| 21 | |
| 22 | // DisablePAFXFAST used to configure the client to not use PA_FX_FAST. |
| 23 | // |
| 24 | // s := NewSettings(DisablePAFXFAST(true)) |
| 25 | func DisablePAFXFAST(b bool) func(*Settings) { |
| 26 | return func(s *Settings) { |
| 27 | s.disablePAFXFast = b |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | // DisablePAFXFAST indicates is the client should disable the use of PA_FX_FAST. |
| 32 | func (s *Settings) DisablePAFXFAST() bool { |
| 33 | return s.disablePAFXFast |
| 34 | } |
| 35 | |
| 36 | // AssumePreAuthentication used to configure the client to assume pre-authentication is required. |
| 37 | // |
| 38 | // s := NewSettings(AssumePreAuthentication(true)) |
| 39 | func AssumePreAuthentication(b bool) func(*Settings) { |
| 40 | return func(s *Settings) { |
| 41 | s.disablePAFXFast = b |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // AssumePreAuthentication indicates if the client should proactively assume using pre-authentication. |
| 46 | func (s *Settings) AssumePreAuthentication() bool { |
| 47 | return s.assumePreAuthentication |
| 48 | } |
| 49 | |
| 50 | // Logger used to configure client with a logger. |
| 51 | // |
| 52 | // s := NewSettings(kt, Logger(l)) |
| 53 | func Logger(l *log.Logger) func(*Settings) { |
| 54 | return func(s *Settings) { |
| 55 | s.logger = l |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // Logger returns the client logger instance. |
| 60 | func (s *Settings) Logger() *log.Logger { |
| 61 | return s.logger |
| 62 | } |
| 63 | |
| 64 | // Log will write to the service's logger if it is configured. |
| 65 | func (cl *Client) Log(format string, v ...interface{}) { |
| 66 | if cl.settings.Logger() != nil { |
| 67 | cl.settings.Logger().Printf(format, v...) |
| 68 | } |
| 69 | } |