Skip to content

Commit b0f5e2e

Browse files
author
Adam Solymos
committed
Replaced all old style logging with jww
1 parent 019220b commit b0f5e2e

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

shopify/shopify.go

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import (
2222
"encoding/json"
2323
"errors"
2424
"fmt"
25-
"log"
2625
"net/http"
2726
"net/http/cookiejar"
2827
"net/url"
2928
"strconv"
3029
"strings"
3130
"time"
31+
jww "github.com/spf13/jwalterweatherman"
3232
)
3333

3434
const (
@@ -67,7 +67,7 @@ func (shopifyClient *Shopify) LoadProducts() {
6767
//var lastId int = shopifyResponse.Products[249].Id
6868

6969
for done == false {
70-
log.Printf("[LoadProducts] - Shopify: Loaded page %v, that's %v products!\n", page, len(shopifyClient.Products))
70+
jww.INFO.Printf("[LoadProducts] - Shopify: Loaded page %v, that's %v products!\n", page, len(shopifyClient.Products))
7171
page++
7272
//get this thread to wait 0.5 seconds
7373
time.Sleep(time.Second / 2)
@@ -97,7 +97,7 @@ func (shopifyClient *Shopify) GetLiveProduct(shopifyID string) (Product, error)
9797
if err != nil {
9898
return shopifyResponse.SingleProduct, err
9999
}
100-
fmt.Printf("[GetLiveProduct] - Product ID: %s\n", strconv.Itoa(shopifyResponse.SingleProduct.ID))
100+
jww.INFO.Printf("[GetLiveProduct] - Product ID: %s\n", strconv.Itoa(shopifyResponse.SingleProduct.ID))
101101

102102
return shopifyResponse.SingleProduct, nil
103103
}
@@ -112,7 +112,7 @@ func (shopifyClient *Shopify) GetOrder(shopifyID string) (Order, error) {
112112
return shopifyResponse.SingleOrder, err
113113
}
114114

115-
fmt.Printf("[GetOrder] - Order id: %s\n", strconv.Itoa(shopifyResponse.SingleOrder.ID))
115+
jww.INFO.Printf("[GetOrder] - Order id: %s\n", strconv.Itoa(shopifyResponse.SingleOrder.ID))
116116

117117
return shopifyResponse.SingleOrder, nil
118118
}
@@ -127,8 +127,6 @@ func (shopifyClient *Shopify) CancelOrder(shopifyID string) (Order, error) {
127127
return shopifyResponse.SingleOrder, err
128128
}
129129

130-
//fmt.Printf("[CancelOrder] - Order: %v\n", shopifyResponse)
131-
132130
return shopifyResponse.SingleOrder, nil
133131
}
134132

@@ -144,8 +142,6 @@ func (shopifyClient *Shopify) PlaceOrder(order OrderResponse) (Order, error) {
144142
return shopifyResponse.SingleOrder, err
145143
}
146144

147-
//fmt.Printf("[PlaceOrder] - Order: %v\n", shopifyResponse.SingleOrder)
148-
149145
return shopifyResponse.SingleOrder, nil
150146
}
151147

@@ -165,7 +161,7 @@ func (shopifyClient *Shopify) ShippingOptions(order Order) ([]ShippingRate, erro
165161
itemsInCartURLStr := cartURLStr + strings.Join(itemsInfo, ",")
166162

167163
completeURL := fmt.Sprintf("https://%s%s%s", shopifyClient.shopifyDomain, baseURLString, itemsInCartURLStr)
168-
log.Printf("[ShippingOptions] - Request URL: %s", completeURL)
164+
jww.INFO.Printf("[ShippingOptions] - Request URL: %s", completeURL)
169165
cookieJar, _ := cookiejar.New(nil)
170166

171167
client := &http.Client{
@@ -178,7 +174,7 @@ func (shopifyClient *Shopify) ShippingOptions(order Order) ([]ShippingRate, erro
178174
defer resp.Body.Close()
179175

180176
if err != nil {
181-
fmt.Printf("[ShippingOptions] - Error executing request : %s", err)
177+
jww.ERROR.Printf("[ShippingOptions] - Error executing request : %s", err)
182178
return shopifyResponse.ShippingRates, err
183179
}
184180

@@ -196,7 +192,7 @@ func (shopifyClient *Shopify) ShippingOptions(order Order) ([]ShippingRate, erro
196192
urlStr = urlStr + v.Encode()
197193

198194
completeURL = fmt.Sprintf("https://%s%s%s", shopifyClient.shopifyDomain, baseURLString, urlStr)
199-
log.Printf("\n\n[ShippingOptions] - Request URL: %s", completeURL)
195+
jww.INFO.Printf("[ShippingOptions] - Request URL: %s", completeURL)
200196

201197
r, err = http.NewRequest("GET", completeURL, nil)
202198

@@ -205,17 +201,15 @@ func (shopifyClient *Shopify) ShippingOptions(order Order) ([]ShippingRate, erro
205201
defer resp.Body.Close()
206202

207203
if err != nil {
208-
fmt.Printf("[ShippingOptions] - Error executing request : %s", err)
204+
jww.ERROR.Printf("[ShippingOptions] - Error executing request : %s", err)
209205
return shopifyResponse.ShippingRates, err
210206
}
211207

212-
//bodyResp, _ := ioutil.ReadAll(resp.Body)
213-
//fmt.Printf("\n\n *****RESPONSE: %#v\n", string(bodyResp))
214208
err = json.NewDecoder(resp.Body).Decode(shopifyResponse)
215209

216210
if err != nil {
217-
fmt.Printf("\n[ShippingOptions] - Decoding error: %#v", err)
218-
fmt.Printf("\n[ShippingOptions] - Response: %#v", resp.Body)
211+
jww.ERROR.Printf("[ShippingOptions] - Decoding error: %#v", err)
212+
jww.ERROR.Printf("[ShippingOptions] - Response: %#v", resp.Body)
219213
return shopifyResponse.ShippingRates, err
220214
}
221215

@@ -243,12 +237,11 @@ func (shopifyClient *Shopify) ShippingOptions(order Order) ([]ShippingRate, erro
243237

244238
func (shopifyClient *Shopify) makeRequest(method string, urlStr string, body interface{}, payload string) error {
245239
url := fmt.Sprintf("https://%s%s%s", shopifyClient.shopifyDomain, baseURLString, urlStr)
246-
log.Printf("\n\n[makeRequest] - Request URL: %s", url)
240+
jww.INFO.Printf("[makeRequest] - Request URL: %s", url)
247241
client := &http.Client{}
248242
buf := new(bytes.Buffer)
249243

250244
if payload != "" {
251-
//fmt.Printf("\n\n\nPAYLOAD string: %#v", payload)
252245
buf = bytes.NewBuffer([]byte(payload))
253246
}
254247
r, err := http.NewRequest(method, url, buf)
@@ -260,25 +253,22 @@ func (shopifyClient *Shopify) makeRequest(method string, urlStr string, body int
260253

261254
defer resp.Body.Close()
262255
if resp.StatusCode == http.StatusNotFound {
263-
fmt.Printf("[makeRequest] - 404 on executing request: %s\n", url)
256+
jww.ERROR.Printf("[makeRequest] - 404 on executing request: %s\n", url)
264257
} else if resp.StatusCode == 429 {
265-
fmt.Printf("[makeRequest] - Rate limited!\n")
258+
jww.ERROR.Printf("[makeRequest] - Rate limited!\n")
266259
rateLimitErr := errors.New("API rate limit exceeded")
267260
return rateLimitErr
268261
}
269262
if err != nil {
270-
fmt.Printf("[makeRequest] - Error executing request : %s", err)
263+
jww.ERROR.Printf("[makeRequest] - Error executing request : %s", err)
271264
return err
272265
}
273266

274-
//bodyResp, _ := ioutil.ReadAll(resp.Body)
275-
//fmt.Printf("\n\n *****RESPONSE: %#v\n", string(bodyResp))
276-
277267
err = json.NewDecoder(resp.Body).Decode(body)
278268

279269
if err != nil {
280-
fmt.Printf("\n[makeRequest] - Decoding error: %#v", err)
281-
fmt.Printf("\n[makeRequest] - Response: %#v", resp.Body)
270+
jww.ERROR.Printf("[makeRequest] - Decoding error: %#v", err)
271+
jww.ERROR.Printf("[makeRequest] - Response: %#v", resp.Body)
282272
return err
283273
}
284274

0 commit comments

Comments
 (0)