do all requests with context
All checks were successful
Build and Publish / Metadata (push) Successful in 14s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 50s
Build and Publish / BuildAndDeployArm64 (push) Successful in 4m22s

This commit is contained in:
matst80
2025-11-05 19:04:56 +01:00
parent 01d8d86c7c
commit 81e2fb5faa
5 changed files with 34 additions and 24 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"context"
"encoding/json"
"fmt"
"net/http"
@@ -26,9 +27,14 @@ func getBaseUrl(country string) string {
return "http://localhost:8082"
}
func FetchItem(sku string, country string) (*index.DataItem, error) {
func FetchItem(ctx context.Context, sku string, country string) (*index.DataItem, error) {
baseUrl := getBaseUrl(country)
res, err := http.Get(fmt.Sprintf("%s/api/by-sku/%s", baseUrl, sku))
req, err := http.NewRequest("GET", fmt.Sprintf("%s/api/by-sku/%s", baseUrl, sku), nil)
req = req.WithContext(ctx)
if err != nil {
return nil, err
}
res, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
@@ -38,8 +44,8 @@ func FetchItem(sku string, country string) (*index.DataItem, error) {
return &item, err
}
func GetItemAddMessage(sku string, qty int, country string, storeId *string) (*messages.AddItem, error) {
item, err := FetchItem(sku, country)
func GetItemAddMessage(ctx context.Context, sku string, qty int, country string, storeId *string) (*messages.AddItem, error) {
item, err := FetchItem(ctx, sku, country)
if err != nil {
return nil, err
}