// Shows the exact `getproductbyvariant` response once NUTRITION_BASE is set. // // Takes the LIVE Fiesta response for a product, runs the same decoration the // endpoint runs, and prints the result. Nothing here is hand-assembled: the // product row is production's, the panel and score are the live catalogue- // intelligence service's, and the code between them is what is deployed. // // go run ./scratch/nutritionlive # product 7101 // go run ./scratch/nutritionlive package main import ( "encoding/json" "fmt" "io" "net/http" "os" "time" "nearle/models" "nearle/services" ) const fiesta = "https://fiesta.nearle.app/live/api/v1/mob/products/getproductbyvariant" type envelope struct { Code int `json:"code"` Details []models.Products `json:"details"` Message string `json:"message"` Status bool `json:"status"` } func main() { tenant, product := "1147", "7101" if len(os.Args) == 3 { tenant, product = os.Args[1], os.Args[2] } base := os.Getenv("NUTRITION_BASE") if base == "" { base = "https://mcp.nearle.ai.in/api" } nutrition := services.NewNutritionService(base) url := fmt.Sprintf("%s?tenantid=%s&productid=%s&variantid=0", fiesta, tenant, product) client := &http.Client{Timeout: 30 * time.Second} response, err := client.Get(url) if err != nil { fmt.Println("fetching the live product:", err) return } defer response.Body.Close() body, err := io.ReadAll(response.Body) if err != nil { fmt.Println("reading the live product:", err) return } var out envelope if err := json.Unmarshal(body, &out); err != nil { fmt.Println("parsing the live product:", err) return } // The same call the endpoint makes, on the same rows. for i := range out.Details { found := nutrition.ForProduct(out.Details[i].Productbrand, out.Details[i].Imageid) out.Details[i].Nutrition = found.Panel out.Details[i].Healthscore = found.Health } encoded, _ := json.MarshalIndent(out, "", " ") fmt.Println(string(encoded)) }