Skip to content

Commit f66c750

Browse files
committed
chore: simplify attachment file writing
1 parent bd02de9 commit f66c750

File tree

4 files changed

+5
-7
lines changed

4 files changed

+5
-7
lines changed

plugin/idp/oauth2/oauth2.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@ func (p *IdentityProvider) UserInfo(token string) (*idp.IdentityProviderUserInfo
9090
if err != nil {
9191
return nil, errors.Wrap(err, "failed to get user information")
9292
}
93+
defer resp.Body.Close()
94+
9395
body, err := io.ReadAll(resp.Body)
9496
if err != nil {
9597
return nil, errors.Wrap(err, "failed to read response body")
9698
}
97-
defer resp.Body.Close()
9899

99100
var claims map[string]any
100101
if err := json.Unmarshal(body, &claims); err != nil {

plugin/scheduler/scheduler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,11 @@ func (s *Scheduler) runJobWithSchedule(ctx context.Context, rj *registeredJob, s
153153
_ = err
154154
}
155155
case <-ctx.Done():
156+
// Stop the timer to prevent it from firing. The timer will be garbage collected.
156157
timer.Stop()
157158
return
158159
case <-s.stopCh:
160+
// Stop the timer to prevent it from firing. The timer will be garbage collected.
159161
timer.Stop()
160162
return
161163
}

plugin/webhook/webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ func Post(requestPayload *WebhookRequestPayload) error {
4949
if err != nil {
5050
return errors.Wrapf(err, "failed to post webhook to %s", requestPayload.URL)
5151
}
52+
defer resp.Body.Close()
5253

5354
b, err := io.ReadAll(resp.Body)
5455
if err != nil {
5556
return errors.Wrapf(err, "failed to read webhook response from %s", requestPayload.URL)
5657
}
57-
defer resp.Body.Close()
5858

5959
if resp.StatusCode < 200 || resp.StatusCode > 299 {
6060
return errors.Errorf("failed to post webhook %s, status code: %d, response body: %s", requestPayload.URL, resp.StatusCode, b)

server/router/api/v1/attachment_service.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,6 @@ func SaveAttachmentBlob(ctx context.Context, profile *profile.Profile, stores *s
317317
if err = os.MkdirAll(dir, os.ModePerm); err != nil {
318318
return errors.Wrap(err, "Failed to create directory")
319319
}
320-
dst, err := os.Create(osPath)
321-
if err != nil {
322-
return errors.Wrap(err, "Failed to create file")
323-
}
324-
defer dst.Close()
325320

326321
// Write the blob to the file.
327322
if err := os.WriteFile(osPath, create.Blob, 0644); err != nil {

0 commit comments

Comments
 (0)