mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-25 10:12:37 +02:00
fix debug
This commit is contained in:
parent
cabd7084fc
commit
e86ab01766
@ -1,9 +1,10 @@
|
|||||||
package piwigo
|
package piwigo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@ -48,7 +49,7 @@ func (p *Piwigo) Post(method string, form *url.Values, resp interface{}) error {
|
|||||||
Result: resp,
|
Result: resp,
|
||||||
}
|
}
|
||||||
|
|
||||||
var raw []byte
|
raw := bytes.NewBuffer([]byte{})
|
||||||
|
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
req, err := http.NewRequest("POST", Url, strings.NewReader(encodedForm))
|
req, err := http.NewRequest("POST", Url, strings.NewReader(encodedForm))
|
||||||
@ -65,14 +66,14 @@ func (p *Piwigo) Post(method string, form *url.Values, resp interface{}) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
defer r.Body.Close()
|
||||||
|
|
||||||
raw, err := ioutil.ReadAll(r.Body)
|
_, err = io.Copy(raw, r.Body)
|
||||||
r.Body.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(raw, &Result)
|
err = json.Unmarshal(raw.Bytes(), &Result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -93,7 +94,7 @@ func (p *Piwigo) Post(method string, form *url.Values, resp interface{}) error {
|
|||||||
|
|
||||||
if os.Getenv("DEBUG") == "1" {
|
if os.Getenv("DEBUG") == "1" {
|
||||||
var RawResult interface{}
|
var RawResult interface{}
|
||||||
err = json.Unmarshal(raw, RawResult)
|
err = json.Unmarshal(raw.Bytes(), &RawResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user