less deps

This commit is contained in:
matst80
2024-11-08 23:10:07 +01:00
parent 1b75f81119
commit 251a0b7bc7
3 changed files with 90 additions and 37 deletions

View File

@@ -4,11 +4,9 @@ import (
"encoding/json"
"fmt"
"log"
"net/http"
"time"
messages "git.tornberg.me/go-cart-actor/proto"
"github.com/matst80/slask-finder/pkg/index"
)
type CartId [16]byte
@@ -58,32 +56,28 @@ func (c *CartGrain) GetLastChange() int64 {
}
func getItemData(sku string) (*messages.AddItem, error) {
res, err := http.Get("https://slask-finder.tornberg.me/api/get/" + sku)
item, err := FetchItem(sku)
if err != nil {
return nil, err
}
defer res.Body.Close()
var item index.DataItem
err = json.NewDecoder(res.Body).Decode(&item)
if err != nil {
return nil, err
}
price := item.GetPrice()
if price == 0 {
priceField, ok := item.GetFields()[4]
if ok {
price := 0
priceField, ok := item.Fields[4]
if ok {
priceFloat, ok := priceField.(float64)
priceFloat, ok := priceField.(float64)
if !ok {
price, ok = priceField.(int)
if !ok {
price, ok = priceField.(int)
if !ok {
return nil, fmt.Errorf("invalid price type")
}
} else {
price = int(priceFloat)
return nil, fmt.Errorf("invalid price type")
}
} else {
price = int(priceFloat)
}
}
if price == 0 {
return nil, fmt.Errorf("invalid price")
}
return &messages.AddItem{
Quantity: 1,
Price: int64(price),