Add context support to GetPriceHistory function

Refactored GetPriceHistory to accept a context parameter, enabling better control over request lifecycle and cancellation. Updated the main function and deferred body close logic to align with the new context usage. This improves code robustness and readability.
This commit is contained in:
2025-01-19 23:54:17 -05:00
parent be3848d0b3
commit 9da603f937
2 changed files with 17 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"context"
"fmt"
"os"
"strconv"
@@ -10,6 +11,7 @@ import (
func main() {
// usage: aisegopher <product_id>
ctx := context.Background()
if len(os.Args) != 2 {
fmt.Println("usage: aisegopher <product_id>")
@@ -23,7 +25,7 @@ func main() {
os.Exit(1)
}
priceHistory, err := aislegopher.GetPriceHistory(productId)
priceHistory, err := aislegopher.GetPriceHistory(ctx, productId)
if err != nil {
fmt.Println("Error getting price history: ", err)