Skip to content

Commit 884a3a7

Browse files
committed
Refactor Client to consolidate handling of Admin mode
1 parent 09aa342 commit 884a3a7

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

sumologic/sumologic_client.go

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,16 @@ func (s *Client) createSumoRequest(method, relativeURL string, body io.Reader) (
5353
}
5454

5555
fullURL := s.BaseURL.ResolveReference(parsedRelativeURL).String()
56-
return createNewRequest(method, fullURL, body, s.AccessID, s.AccessKey, s.AuthJwt)
56+
req, err := createNewRequest(method, fullURL, body, s.AccessID, s.AccessKey, s.AuthJwt)
57+
if err != nil {
58+
return nil, err
59+
}
60+
61+
if s.IsInAdminMode {
62+
req.Header.Add("isAdminMode", "true")
63+
}
64+
65+
return req, nil
5766
}
5867

5968
func createNewRequest(method, url string, body io.Reader, accessID string, accessKey string, authJwt string) (*http.Request, error) {
@@ -88,10 +97,6 @@ func (s *Client) Post(urlPath string, payload interface{}) ([]byte, error) {
8897
return nil, err
8998
}
9099

91-
if s.IsInAdminMode {
92-
req.Header.Add("isAdminMode", "true")
93-
}
94-
95100
<-rateLimiter.C
96101
resp, err := s.httpClient.Do(req)
97102

@@ -119,10 +124,6 @@ func (s *Client) PostRawPayload(urlPath string, payload string) ([]byte, error)
119124
return nil, err
120125
}
121126

122-
if s.IsInAdminMode {
123-
req.Header.Add("isAdminMode", "true")
124-
}
125-
126127
<-rateLimiter.C
127128
resp, err := s.httpClient.Do(req)
128129

@@ -157,10 +158,6 @@ func (s *Client) Put(urlPath string, payload interface{}) ([]byte, error) {
157158
}
158159
req.Header.Add("If-Match", etag)
159160

160-
if s.IsInAdminMode {
161-
req.Header.Add("isAdminMode", "true")
162-
}
163-
164161
<-rateLimiter.C
165162
resp, err := s.httpClient.Do(req)
166163

@@ -192,10 +189,6 @@ func (s *Client) GetWithErrOpt(urlPath string, return404Err bool) ([]byte, strin
192189
return nil, "", err
193190
}
194191

195-
if s.IsInAdminMode {
196-
req.Header.Add("isAdminMode", "true")
197-
}
198-
199192
<-rateLimiter.C
200193
resp, err := s.httpClient.Do(req)
201194
if err != nil {
@@ -229,10 +222,6 @@ func (s *Client) Delete(urlPath string) ([]byte, error) {
229222
return nil, err
230223
}
231224

232-
if s.IsInAdminMode {
233-
req.Header.Add("isAdminMode", "true")
234-
}
235-
236225
<-rateLimiter.C
237226
resp, err := s.httpClient.Do(req)
238227

0 commit comments

Comments
 (0)