package main import ( "bytes" "encoding/json" "fmt" "io" "net/http" "os" ) func env(key, fallback string) string { if v := os.Getenv(key); v != "" { return v }; return fallback } func postJSON(url string, payload any, headers map[string]string) map[string]any { body, _ := json.Marshal(payload) req, _ := http.NewRequest("POST", url, bytes.NewReader(body)) req.Header.Set("Content-Type", "application/json") for k, v := range headers { req.Header.Set(k, v) } res, err := http.DefaultClient.Do(req); if err != nil { panic(err) } defer res.Body.Close() data, _ := io.ReadAll(res.Body) var out map[string]any json.Unmarshal(data, &out) return out } func main() { identityURL := env("DECISIOQ_IDENTITY_URL", "https://identity.vinquery.com/connect/token") catalogURL := env("DECISIOQ_DKS_URL", "https://dks.vinquery.com") decisionServiceURL := env("DECISIOQ_DDE_URL", "https://dde.vinquery.com") audience := env("DECISIOQ_AUDIENCE", "vinquery:api:decisioq") tokenResult := postJSON(identityURL, map[string]string{"clientId": os.Getenv("DECISIOQ_CLIENT_ID"), "clientSecret": os.Getenv("DECISIOQ_CLIENT_SECRET"), "audience": audience}, nil) token := tokenResult["jwtToken"].(string) req, _ := http.NewRequest("GET", catalogURL+"/decisioncatalog/decisions/AUTO-REPR-070", nil) req.Header.Set("Authorization", "Bearer "+token) http.DefaultClient.Do(req) payloadFile, _ := os.ReadFile("../auto-repr-070-execute.json") var payload map[string]any json.Unmarshal(payloadFile, &payload) result := postJSON(decisionServiceURL+"/api/v1/decide", payload, map[string]string{"Authorization": "Bearer "+token, "X-Correlation-Id": "auto-repr-070-demo-001"}) pretty, _ := json.MarshalIndent(result, "", " ") fmt.Println(string(pretty)) }