blob: 516c823140e4a72e4a16f38b8b7e4c65e850d013 [file] [log] [blame]
onkarkundargi72cfd362020-02-27 12:34:37 +05301package client
2
3import "log"
4
5// Settings holds optional client settings.
6type 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.
14func 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))
25func 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.
32func (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))
39func 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.
46func (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))
53func 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.
60func (s *Settings) Logger() *log.Logger {
61 return s.logger
62}
63
64// Log will write to the service's logger if it is configured.
65func (cl *Client) Log(format string, v ...interface{}) {
66 if cl.settings.Logger() != nil {
67 cl.settings.Logger().Printf(format, v...)
68 }
69}