36 lines
728 B
Go
36 lines
728 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.s10n:8080"
|
|
}
|
|
if country == "se" {
|
|
return "http://s10n-se.s10n:8080"
|
|
}
|
|
return "http://localhost:8082"
|
|
}
|
|
|
|
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
|
|
}
|