From f5290ad786492b60013f1982d41fa27e01abf1a0 Mon Sep 17 00:00:00 2001 From: Cyberhan123 <255542417@qq.com> Date: Sun, 10 Dec 2023 12:44:44 +0800 Subject: [PATCH] fix defer f.Close() order --- api/api.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/api.go b/api/api.go index aaa59cf..0b15468 100644 --- a/api/api.go +++ b/api/api.go @@ -470,10 +470,10 @@ func (a *Api) downloadTempFile(url string, progressbar *progressbar.ProgressBar) } file, err := os.Create(filename) - defer file.Close() if err != nil { return "", err } + defer file.Close() req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { @@ -651,10 +651,10 @@ type RepoInfo struct { func (r *ApiRepo) Info() (*RepoInfo, error) { res, err := r.InfoRequest() - defer res.Body.Close() if err != nil { return nil, err } + defer res.Body.Close() var responseData RepoInfo err = json.NewDecoder(res.Body).Decode(&responseData)