@@ -59,25 +59,6 @@ func (c *Client) do(method, path string, input, output interface{}) error {
5959 return nil
6060}
6161
62- func (c * Client ) doAndSaveHeaders (method , path string , input , output interface {}) (http.Header , error ) {
63- url := shippoAPIBaseURL + path
64-
65- req , err := c .createRequest (method , url , input )
66- if err != nil {
67- return nil , fmt .Errorf ("Error creating request object: %s" , err .Error ())
68- }
69-
70- headers , err := c .executeRequestAndSaveHeaders (req , output )
71- if err != nil {
72- if aerr , ok := err .(* errors.APIError ); ok {
73- return nil , aerr
74- }
75- return nil , fmt .Errorf ("Error executing request: %s" , err .Error ())
76- }
77-
78- return headers , nil
79- }
80-
8162func (c * Client ) doList (method , path string , input interface {}, outputCallback listOutputCallback ) error {
8263 nextURL := shippoAPIBaseURL + path + "?results=25"
8364
@@ -214,54 +195,6 @@ func (c *Client) executeRequest(req *http.Request, output interface{}) (err erro
214195 }
215196}
216197
217- func (c * Client ) executeRequestAndSaveHeaders (req * http.Request , output interface {}) (headers http.Header , err error ) {
218- if c .logger != nil {
219- defer func () {
220- if err != nil {
221- c .logPrintf ("Client.executeRequest() error: %s" , err .Error ())
222- }
223- }()
224- }
225-
226- httpClient := http.Client {
227- CheckRedirect : func (req * http.Request , via []* http.Request ) error {
228- return http .ErrUseLastResponse
229- },
230- }
231-
232- res , err := httpClient .Do (req )
233- if err != nil {
234- return nil , fmt .Errorf ("Error making HTTP request: %s" , err .Error ())
235- }
236- defer res .Body .Close ()
237-
238- resData , err := ioutil .ReadAll (res .Body )
239- if err != nil {
240- return nil , fmt .Errorf ("Error reading response body data: %s" , err .Error ())
241- }
242-
243- if c .logger != nil {
244- c .logPrintf ("Client.executeRequest() response: status=%q, body=%q" , res .Status , string (resData ))
245- }
246-
247- if res .StatusCode >= 200 && res .StatusCode < 300 {
248- if output != nil && len (resData ) > 0 {
249- if err := json .Unmarshal (resData , output ); err != nil {
250- return nil , fmt .Errorf ("Error unmarshaling response data: %s" , err .Error ())
251- }
252- }
253-
254- return res .Header , nil
255- } else if res .StatusCode == 302 {
256- return res .Header , nil
257- }
258-
259- return nil , & errors.APIError {
260- Status : res .StatusCode ,
261- ResponseBody : resData ,
262- }
263- }
264-
265198func (c * Client ) logPrintf (format string , args ... interface {}) {
266199 if c .logger != nil {
267200 c .logger .Printf (format , args ... )
0 commit comments