@@ -22,21 +22,33 @@ import (
2222
2323// Master struct/object
2424type Client struct {
25+ // Config
2526 config ClientConfig
26- http * http.Client
2727
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
3339}
3440
3541// Options/Variables for Client
3642type ClientConfig struct {
3743 // Interface which implements the APIIntegration patterns. Integration handles all server/endpoint specific configuration, auth and vars.
3844 Integration APIIntegration
3945
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+
4052 // HideSenitiveData controls if sensitive data will be visible in logs. Debug option which should be True in production use.
4153 HideSensitiveData bool `json:"hide_sensitive_data"`
4254
@@ -80,18 +92,17 @@ type ClientConfig struct {
8092}
8193
8294// 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 {
8697 zapLogger , err := zap .NewProduction ()
87- sugar = zapLogger .Sugar ()
88-
8998 if err != nil {
9099 return nil , err
91100 }
101+
102+ c .Sugar = zapLogger .Sugar ()
92103 }
93104
94- err := c .validateClientConfig (populateDefaultValues )
105+ err := c .validateClientConfig ()
95106 if err != nil {
96107 return nil , fmt .Errorf ("invalid configuration: %v" , err )
97108 }
@@ -101,16 +112,17 @@ func (c ClientConfig) BuildClient(populateDefaultValues bool, sugar *zap.Sugared
101112 }
102113
103114 // 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 {
105116 return nil , fmt .Errorf ("Failed to set up redirect handler: %v" , err )
106117 }
107118
119+ // TODO refactor concurrency
108120 var concurrencyHandler * concurrency.ConcurrencyHandler
109121 if c .EnableConcurrencyManagement {
110122 concurrencyMetrics := & concurrency.ConcurrencyMetrics {}
111123 concurrencyHandler = concurrency .NewConcurrencyHandler (
112124 c .MaxConcurrentRequests ,
113- sugar ,
125+ c . Sugar ,
114126 concurrencyMetrics ,
115127 )
116128 } else {
@@ -121,12 +133,12 @@ func (c ClientConfig) BuildClient(populateDefaultValues bool, sugar *zap.Sugared
121133 Integration : & c .Integration ,
122134 http : httpClient ,
123135 config : c ,
124- Sugar : sugar ,
136+ Sugar : c . Sugar ,
125137 Concurrency : concurrencyHandler ,
126138 }
127139
128140 if len (client .config .CustomCookies ) > 0 {
129- client .loadCustomCookies (c . CustomCookies )
141+ client .loadCustomCookies ()
130142 }
131143
132144 return client , nil
0 commit comments