Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ jobs:
go-version-file: 'go.mod'

- name: go-lint
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
4 changes: 3 additions & 1 deletion api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ func (client *Client) Call(req *http.Request, dst any, opts ...Option) error {
if err != nil {
return err
}
defer res.Body.Close()
defer func() {
_ = res.Body.Close()
}()

// Decode response
resp := Response{
Expand Down
4 changes: 3 additions & 1 deletion api/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func (client *Client) ExportRaw(params *ExportRawParams, opts ...Option) ([]byte
if err != nil {
return nil, err
}
defer res.Body.Close()
defer func() {
_ = res.Body.Close()
}()

if res.StatusCode != http.StatusOK {
return nil, fmt.Errorf("CTFd responded with unexpected status code: got %d", res.StatusCode)
Expand Down
12 changes: 9 additions & 3 deletions api/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ func (client *Client) GetFileContent(file *File, opts ...Option) ([]byte, error)
if err != nil {
return nil, err
}
defer res.Body.Close()
defer func() {
_ = res.Body.Close()
}()

return io.ReadAll(res.Body)
}
Expand All @@ -112,7 +114,9 @@ func encodeMultipart(values map[string]any) (io.Reader, string, error) {
var content []byte
// Avoid closer goleak
if x, ok := v.(io.Closer); ok {
defer x.Close()
defer func() {
_ = x.Close()
}()
}
// Add file content or field
if file, ok := v.(*InputFile); ok {
Expand Down Expand Up @@ -152,7 +156,9 @@ func encodeMultipart(values map[string]any) (io.Reader, string, error) {
return nil, "", err
}
}
w.Close()
if err := w.Close(); err != nil {
return nil, "", err
}
return &b, w.FormDataContentType(), nil
}

Expand Down
4 changes: 3 additions & 1 deletion api/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ func (client *Client) Login(params *LoginParams, opts ...Option) error {
if err != nil {
return err
}
defer res.Body.Close()
defer func() {
_ = res.Body.Close()
}()

if res.StatusCode != http.StatusOK {
return fmt.Errorf("CTFd responded with status code %d", res.StatusCode)
Expand Down
4 changes: 3 additions & 1 deletion api/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ func (client *Client) Logout(opts ...Option) error {
if err != nil {
return err
}
defer res.Body.Close()
defer func() {
_ = res.Body.Close()
}()

if res.StatusCode != http.StatusOK {
return fmt.Errorf("CTFd responded with status code %d", res.StatusCode)
Expand Down
4 changes: 3 additions & 1 deletion api/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ func (client *Client) HeadNotifications(params *HeadNotificationsParams, opts ..
if err != nil {
return 0, err
}
defer res.Body.Close()
defer func() {
_ = res.Body.Close()
}()

// Check status code
if res.StatusCode != http.StatusOK {
Expand Down
8 changes: 6 additions & 2 deletions api/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ func (client *Client) Register(params *RegisterParams, opts ...Option) error {
if err != nil {
return err
}
defer res.Body.Close()
defer func() {
_ = res.Body.Close()
}()

if res.StatusCode != http.StatusOK {
return fmt.Errorf("CTFd responded with status code %d, which could be due to email reuse", res.StatusCode)
Expand All @@ -39,7 +41,9 @@ func (client *Client) Register(params *RegisterParams, opts ...Option) error {
if err != nil {
return err
}
defer res.Body.Close()
defer func() {
_ = res.Body.Close()
}()

nonce, err := getNonce(res.Body)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion api/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func (client *Client) Reset(params *ResetParams, opts ...Option) error {
if err != nil {
return errors.Wrap(err, "CTFd responded with error")
}
defer res.Body.Close()
defer func() {
_ = res.Body.Close()
}()

if res.StatusCode != http.StatusOK {
return fmt.Errorf("CTFd responded with status code %d", res.StatusCode)
Expand Down
4 changes: 3 additions & 1 deletion api/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ func (client *Client) Setup(params *SetupParams, opts ...Option) error {
if err != nil {
return err
}
defer res.Body.Close()
defer func() {
_ = res.Body.Close()
}()

if res.StatusCode != http.StatusOK {
return fmt.Errorf("CTFd responded with status code %d", res.StatusCode)
Expand Down
4 changes: 3 additions & 1 deletion api/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ func GetNonceAndSession(url string, opts ...Option) (nonce string, session strin
if err != nil {
return "", "", err
}
defer res.Body.Close()
defer func() {
_ = res.Body.Close()
}()

return getNonceAndSession(res)
}
Expand Down
Loading