mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-24 17:52:36 +02:00
remove defer close in a loop
This commit is contained in:
parent
9015f2e8e5
commit
b60ae43bf3
@ -68,7 +68,7 @@ func (p *Piwigo) Upload(file *piwigotools.FileToUpload, stat *piwigotools.FileTo
|
|||||||
|
|
||||||
ok := true
|
ok := true
|
||||||
wg.Add(nbJobs)
|
wg.Add(nbJobs)
|
||||||
for j := 0; j < nbJobs; j++ {
|
for range nbJobs {
|
||||||
go p.UploadChunk(file, chunks, wg, stat, &ok)
|
go p.UploadChunk(file, chunks, wg, stat, &ok)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
@ -52,10 +52,14 @@ func (p *Piwigo) Post(method string, form *url.Values, resp interface{}) error {
|
|||||||
|
|
||||||
raw := bytes.NewBuffer([]byte{})
|
raw := bytes.NewBuffer([]byte{})
|
||||||
|
|
||||||
for i := 0; i < 3; i++ {
|
for i := range 3 {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
time.Sleep(time.Second) // wait 1 sec before retry
|
time.Sleep(time.Second) // wait 1 sec before retry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func() {
|
||||||
|
|
||||||
|
}()
|
||||||
req, err := http.NewRequest("POST", Url, strings.NewReader(encodedForm))
|
req, err := http.NewRequest("POST", Url, strings.NewReader(encodedForm))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -70,15 +74,16 @@ func (p *Piwigo) Post(method string, form *url.Values, resp interface{}) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
defer r.Body.Close()
|
|
||||||
|
|
||||||
_, err = io.Copy(raw, r.Body)
|
_, err = io.Copy(raw, r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
_ = r.Body.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(raw.Bytes(), &Result)
|
err = json.Unmarshal(raw.Bytes(), &Result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
_ = r.Body.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,6 +94,7 @@ func (p *Piwigo) Post(method string, form *url.Values, resp interface{}) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_ = r.Body.Close()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user