@@ -8,21 +8,15 @@ import (
88 "bytes"
99 "crypto/tls"
1010 "crypto/x509"
11- "encoding/json"
12- "encoding/xml"
1311 "errors"
1412 "fmt"
1513 "io"
1614 "io/ioutil"
1715 "log"
18- "mime/multipart"
1916 "net/http"
2017 "net/url"
21- "os"
22- "path/filepath"
2318 "reflect"
2419 "regexp"
25- "runtime"
2620 "strings"
2721 "sync"
2822 "time"
@@ -649,13 +643,7 @@ func (c *Client) SetRootCertificate(pemFilePath string) *Client {
649643// resty.SetOutputDirectory("/save/http/response/here")
650644//
651645func (c * Client ) SetOutputDirectory (dirPath string ) * Client {
652- err := createDirectory (dirPath )
653- if err != nil {
654- c .Log .Printf ("ERROR [%v]" , err )
655- }
656-
657646 c .outputDirectory = dirPath
658-
659647 return c
660648}
661649
@@ -834,155 +822,3 @@ type File struct {
834822func (f * File ) String () string {
835823 return fmt .Sprintf ("ParamName: %v; FileName: %v" , f .ParamName , f .Name )
836824}
837-
838- //
839- // Helper methods
840- //
841-
842- // IsStringEmpty method tells whether given string is empty or not
843- func IsStringEmpty (str string ) bool {
844- return (len (strings .TrimSpace (str )) == 0 )
845- }
846-
847- // DetectContentType method is used to figure out `Request.Body` content type for request header
848- func DetectContentType (body interface {}) string {
849- contentType := plainTextType
850- kind := kindOf (body )
851- switch kind {
852- case reflect .Struct , reflect .Map :
853- contentType = jsonContentType
854- case reflect .String :
855- contentType = plainTextType
856- default :
857- if b , ok := body .([]byte ); ok {
858- contentType = http .DetectContentType (b )
859- } else if kind == reflect .Slice {
860- contentType = jsonContentType
861- }
862- }
863-
864- return contentType
865- }
866-
867- // IsJSONType method is to check JSON content type or not
868- func IsJSONType (ct string ) bool {
869- return jsonCheck .MatchString (ct )
870- }
871-
872- // IsXMLType method is to check XML content type or not
873- func IsXMLType (ct string ) bool {
874- return xmlCheck .MatchString (ct )
875- }
876-
877- // Unmarshal content into object from JSON or XML
878- // Deprecated: kept for backward compatibility
879- func Unmarshal (ct string , b []byte , d interface {}) (err error ) {
880- if IsJSONType (ct ) {
881- err = json .Unmarshal (b , d )
882- } else if IsXMLType (ct ) {
883- err = xml .Unmarshal (b , d )
884- }
885-
886- return
887- }
888-
889- // Unmarshalc content into object from JSON or XML
890- func Unmarshalc (c * Client , ct string , b []byte , d interface {}) (err error ) {
891- if IsJSONType (ct ) {
892- err = c .JSONUnmarshal (b , d )
893- } else if IsXMLType (ct ) {
894- err = xml .Unmarshal (b , d )
895- }
896-
897- return
898- }
899-
900- func getLogger (w io.Writer ) * log.Logger {
901- return log .New (w , "RESTY " , log .LstdFlags )
902- }
903-
904- func addFile (w * multipart.Writer , fieldName , path string ) error {
905- file , err := os .Open (path )
906- if err != nil {
907- return err
908- }
909- defer func () {
910- _ = file .Close ()
911- }()
912-
913- part , err := w .CreateFormFile (fieldName , filepath .Base (path ))
914- if err != nil {
915- return err
916- }
917- _ , err = io .Copy (part , file )
918-
919- return err
920- }
921-
922- func addFileReader (w * multipart.Writer , f * File ) error {
923- part , err := w .CreateFormFile (f .ParamName , f .Name )
924- if err != nil {
925- return err
926- }
927- _ , err = io .Copy (part , f .Reader )
928-
929- return err
930- }
931-
932- func getPointer (v interface {}) interface {} {
933- vv := valueOf (v )
934- if vv .Kind () == reflect .Ptr {
935- return v
936- }
937- return reflect .New (vv .Type ()).Interface ()
938- }
939-
940- func isPayloadSupported (m string , allowMethodGet bool ) bool {
941- return (m == MethodPost || m == MethodPut || m == MethodDelete || m == MethodPatch || (allowMethodGet && m == MethodGet ))
942- }
943-
944- func typeOf (i interface {}) reflect.Type {
945- return indirect (valueOf (i )).Type ()
946- }
947-
948- func valueOf (i interface {}) reflect.Value {
949- return reflect .ValueOf (i )
950- }
951-
952- func indirect (v reflect.Value ) reflect.Value {
953- return reflect .Indirect (v )
954- }
955-
956- func kindOf (v interface {}) reflect.Kind {
957- return typeOf (v ).Kind ()
958- }
959-
960- func createDirectory (dir string ) (err error ) {
961- if _ , err = os .Stat (dir ); err != nil {
962- if os .IsNotExist (err ) {
963- if err = os .MkdirAll (dir , 0755 ); err != nil {
964- return
965- }
966- }
967- }
968- return
969- }
970-
971- func canJSONMarshal (contentType string , kind reflect.Kind ) bool {
972- return IsJSONType (contentType ) && (kind == reflect .Struct || kind == reflect .Map )
973- }
974-
975- func functionName (i interface {}) string {
976- return runtime .FuncForPC (reflect .ValueOf (i ).Pointer ()).Name ()
977- }
978-
979- func acquireBuffer () * bytes.Buffer {
980- return bufPool .Get ().(* bytes.Buffer )
981- }
982-
983- func releaseBuffer (buf * bytes.Buffer ) {
984- if buf != nil {
985- buf .Reset ()
986- bufPool .Put (buf )
987- }
988- }
0 commit comments