update go samples

This commit is contained in:
William Cheng 2020-05-03 12:42:48 +08:00
parent cd88c06372
commit c98499454c
2 changed files with 20 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
@ -381,6 +382,15 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
*s = string(b) *s = string(b)
return nil 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 xmlCheck.MatchString(contentType) {
if err = xml.Unmarshal(b, v); err != nil { if err = xml.Unmarshal(b, v); err != nil {
return err return err

View File

@ -17,6 +17,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
@ -384,6 +385,15 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
*s = string(b) *s = string(b)
return nil 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 xmlCheck.MatchString(contentType) {
if err = xml.Unmarshal(b, v); err != nil { if err = xml.Unmarshal(b, v); err != nil {
return err return err