Skip to content

Commit

Permalink
Fixed type checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhomber committed Aug 10, 2019
1 parent 133ce9c commit be15f63
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
30 changes: 30 additions & 0 deletions auspost/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,33 @@ func (c *Client) EnableTrace() *Client {

return c
}

func spewTrace(resp *resty.Response, err error) {
fmt.Println("AusPost API Request")
fmt.Println("===================")
fmt.Println()
fmt.Println("Request Info:")
fmt.Println("URL :", resp.Request.URL)
fmt.Println()
fmt.Println("Response Info:")
fmt.Println("Error :", err)
fmt.Println("Status Code:", resp.StatusCode())
fmt.Println("Status :", resp.Status())
fmt.Println("Time :", resp.Time())
fmt.Println("Received At:", resp.ReceivedAt())
fmt.Println("Body :\n", resp)
fmt.Println()

fmt.Println("Request Trace Info:")
ti := resp.Request.TraceInfo()
fmt.Println("DNSLookup :", ti.DNSLookup)
fmt.Println("ConnTime :", ti.ConnTime)
fmt.Println("TLSHandshake :", ti.TLSHandshake)
fmt.Println("ServerTime :", ti.ServerTime)
fmt.Println("ResponseTime :", ti.ResponseTime)
fmt.Println("TotalTime :", ti.TotalTime)
fmt.Println("IsConnReused :", ti.IsConnReused)
fmt.Println("IsConnWasIdle:", ti.IsConnWasIdle)
fmt.Println("ConnIdleTime :", ti.ConnIdleTime)
fmt.Println()
}
30 changes: 3 additions & 27 deletions auspost/postcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package auspost

import (
"errors"
"fmt"
"github.com/rhomber/auspost-postcode/auspost/model"
"strconv"
)
Expand Down Expand Up @@ -30,38 +29,15 @@ func (c *Client) PostcodeSearch(q string, state string, excludePostboxFlag bool)
Get(c.getUrl(ausPostUriPostcodeSearch))

if c.trace {
fmt.Println("AusPost API Request")
fmt.Println("===================")
fmt.Println()
fmt.Println("Response Info:")
fmt.Println("Error :", err)
fmt.Println("Status Code:", resp.StatusCode())
fmt.Println("Status :", resp.Status())
fmt.Println("Time :", resp.Time())
fmt.Println("Received At:", resp.ReceivedAt())
fmt.Println("Body :\n", resp)
fmt.Println()

fmt.Println("Request Trace Info:")
ti := resp.Request.TraceInfo()
fmt.Println("DNSLookup :", ti.DNSLookup)
fmt.Println("ConnTime :", ti.ConnTime)
fmt.Println("TLSHandshake :", ti.TLSHandshake)
fmt.Println("ServerTime :", ti.ServerTime)
fmt.Println("ResponseTime :", ti.ResponseTime)
fmt.Println("TotalTime :", ti.TotalTime)
fmt.Println("IsConnReused :", ti.IsConnReused)
fmt.Println("IsConnWasIdle:", ti.IsConnWasIdle)
fmt.Println("ConnIdleTime :", ti.ConnIdleTime)
fmt.Println()
spewTrace(resp, err)
}

if err != nil {
return model.PostcodeSearchResult{}, err
}

if r, ok := resp.Result().(model.PostcodeSearchResult); ok {
return r, nil
if r, ok := resp.Result().(*model.PostcodeSearchResult); ok {
return *r, nil
}

return model.PostcodeSearchResult{}, ErrInvalidResult
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/rhomber/auspost-postcode

go 1.12

require github.com/go-resty/resty/v2 v2.0.0 // indirect
require github.com/go-resty/resty/v2 v2.0.0

0 comments on commit be15f63

Please sign in to comment.