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