add country
Some checks failed
Build and Publish / BuildAndDeploy (push) Successful in 4m29s
Build and Publish / BuildAndDeployAmd64 (push) Has been cancelled

This commit is contained in:
2025-09-28 09:41:07 +02:00
parent 5c7b8d87e8
commit 8c8ff75b2d
6 changed files with 236 additions and 141 deletions

View File

@@ -4,23 +4,23 @@ import (
"encoding/json"
"fmt"
"net/http"
"os"
"github.com/matst80/slask-finder/pkg/index"
)
/** end */
var baseUrl string
func init() {
baseUrl = "https://slask-finder.tornberg.me"
envUrl := os.Getenv("BASE_URL")
if envUrl != "" {
baseUrl = envUrl
// 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) (*index.DataItem, error) {
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