[Go-client] Fix inability to download files (#9812)

* Revert a change to the Go Client code that broke
the ability to download files. This reverts the change
from 14d41310b9

* Missed import for "io/ioutil"

* update samples

Co-authored-by: icubbon <icubbon@gmail.com>
This commit is contained in:
William Cheng
2021-06-19 11:23:05 +08:00
committed by GitHub
parent 70fb429c98
commit c5405aa59a
4 changed files with 40 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"mime/multipart"
"net/http"
@@ -419,6 +420,15 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
*s = string(b)
return nil
}
if f, ok := v.(**os.File); ok {
*f, err = ioutil.TempFile("", "HttpClientFile")
if err != nil {
return
}
_, err = (*f).Write(b)
_, err = (*f).Seek(0, io.SeekStart)
return
}
if xmlCheck.MatchString(contentType) {
if err = xml.Unmarshal(b, v); err != nil {
return err

View File

@@ -18,6 +18,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"mime/multipart"
"net/http"
@@ -374,6 +375,15 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
*s = string(b)
return nil
}
if f, ok := v.(**os.File); ok {
*f, err = ioutil.TempFile("", "HttpClientFile")
if err != nil {
return
}
_, err = (*f).Write(b)
_, err = (*f).Seek(0, io.SeekStart)
return
}
if xmlCheck.MatchString(contentType) {
if err = xml.Unmarshal(b, v); err != nil {
return err

View File

@@ -18,6 +18,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"mime/multipart"
"net/http"
@@ -359,6 +360,15 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
*s = string(b)
return nil
}
if f, ok := v.(**os.File); ok {
*f, err = ioutil.TempFile("", "HttpClientFile")
if err != nil {
return
}
_, err = (*f).Write(b)
_, err = (*f).Seek(0, io.SeekStart)
return
}
if xmlCheck.MatchString(contentType) {
if err = xml.Unmarshal(b, v); err != nil {
return err

View File

@@ -18,6 +18,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"mime/multipart"
"net/http"
@@ -387,6 +388,15 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
*s = string(b)
return nil
}
if f, ok := v.(**os.File); ok {
*f, err = ioutil.TempFile("", "HttpClientFile")
if err != nil {
return
}
_, err = (*f).Write(b)
_, err = (*f).Seek(0, io.SeekStart)
return
}
if xmlCheck.MatchString(contentType) {
if err = xml.Unmarshal(b, v); err != nil {
return err