Files
go-cart-actor/product-fetcher.go
Mats Törnberg 8c8ff75b2d
Some checks failed
Build and Publish / BuildAndDeploy (push) Successful in 4m29s
Build and Publish / BuildAndDeployAmd64 (push) Has been cancelled
add country
2025-09-28 09:41:07 +02:00

33 lines
673 B
Go

package main
import (
"encoding/json"
"fmt"
"net/http"
"github.com/matst80/slask-finder/pkg/index"
)
// TODO make this configurable
func getBaseUrl(country string) string {
// if country == "se" {
// return "http://s10n-se:8080"
// }
if country == "no" {
return "http://s10n-no:8080"
}
return "https://slask-finder.tornberg.me"
}
func FetchItem(sku string, country string) (*index.DataItem, error) {
baseUrl := getBaseUrl(country)
res, err := http.Get(fmt.Sprintf("%s/api/by-sku/%s", baseUrl, sku))
if err != nil {
return nil, err
}
defer res.Body.Close()
var item index.DataItem
err = json.NewDecoder(res.Body).Decode(&item)
return &item, err
}