@@ -22,21 +22,33 @@ import (
22
22
23
23
// Master struct/object
24
24
type Client struct {
25
+ // Config
25
26
config ClientConfig
26
- http * http.Client
27
27
28
- AuthToken string
29
- AuthTokenExpiry time.Time
30
- Sugar * zap.SugaredLogger
31
- Concurrency * concurrency.ConcurrencyHandler
32
- Integration * APIIntegration
28
+ // Integration
29
+ Integration * APIIntegration
30
+
31
+ // Executor
32
+ http * http.Client
33
+
34
+ // Logger
35
+ Sugar * zap.SugaredLogger
36
+
37
+ // Concurrency Mananger
38
+ Concurrency * concurrency.ConcurrencyHandler
33
39
}
34
40
35
41
// Options/Variables for Client
36
42
type ClientConfig struct {
37
43
// Interface which implements the APIIntegration patterns. Integration handles all server/endpoint specific configuration, auth and vars.
38
44
Integration APIIntegration
39
45
46
+ // TODO
47
+ Sugar * zap.SugaredLogger
48
+
49
+ // Wether or not empty values will be set or an error thrown for missing items.
50
+ PopulateDefaultValues bool
51
+
40
52
// HideSenitiveData controls if sensitive data will be visible in logs. Debug option which should be True in production use.
41
53
HideSensitiveData bool `json:"hide_sensitive_data"`
42
54
@@ -80,18 +92,17 @@ type ClientConfig struct {
80
92
}
81
93
82
94
// BuildClient creates a new HTTP client with the provided configuration.
83
- func (c ClientConfig ) BuildClient (populateDefaultValues bool , sugar * zap.SugaredLogger ) (* Client , error ) {
84
-
85
- if sugar == nil {
95
+ func (c ClientConfig ) Build () (* Client , error ) {
96
+ if c .Sugar == nil {
86
97
zapLogger , err := zap .NewProduction ()
87
- sugar = zapLogger .Sugar ()
88
-
89
98
if err != nil {
90
99
return nil , err
91
100
}
101
+
102
+ c .Sugar = zapLogger .Sugar ()
92
103
}
93
104
94
- err := c .validateClientConfig (populateDefaultValues )
105
+ err := c .validateClientConfig ()
95
106
if err != nil {
96
107
return nil , fmt .Errorf ("invalid configuration: %v" , err )
97
108
}
@@ -101,16 +112,17 @@ func (c ClientConfig) BuildClient(populateDefaultValues bool, sugar *zap.Sugared
101
112
}
102
113
103
114
// TODO refactor redirects
104
- if err := redirecthandler .SetupRedirectHandler (httpClient , c .FollowRedirects , c .MaxRedirects , sugar ); err != nil {
115
+ if err := redirecthandler .SetupRedirectHandler (httpClient , c .FollowRedirects , c .MaxRedirects , c . Sugar ); err != nil {
105
116
return nil , fmt .Errorf ("Failed to set up redirect handler: %v" , err )
106
117
}
107
118
119
+ // TODO refactor concurrency
108
120
var concurrencyHandler * concurrency.ConcurrencyHandler
109
121
if c .EnableConcurrencyManagement {
110
122
concurrencyMetrics := & concurrency.ConcurrencyMetrics {}
111
123
concurrencyHandler = concurrency .NewConcurrencyHandler (
112
124
c .MaxConcurrentRequests ,
113
- sugar ,
125
+ c . Sugar ,
114
126
concurrencyMetrics ,
115
127
)
116
128
} else {
@@ -121,12 +133,12 @@ func (c ClientConfig) BuildClient(populateDefaultValues bool, sugar *zap.Sugared
121
133
Integration : & c .Integration ,
122
134
http : httpClient ,
123
135
config : c ,
124
- Sugar : sugar ,
136
+ Sugar : c . Sugar ,
125
137
Concurrency : concurrencyHandler ,
126
138
}
127
139
128
140
if len (client .config .CustomCookies ) > 0 {
129
- client .loadCustomCookies (c . CustomCookies )
141
+ client .loadCustomCookies ()
130
142
}
131
143
132
144
return client , nil
0 commit comments