settings.go 1.7 KB

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