From bb3fb8867797299d8a76d228da65dde2303ead53 Mon Sep 17 00:00:00 2001 From: guergabo Date: Wed, 14 Jun 2023 10:07:28 -0500 Subject: [PATCH 1/3] fix(go-http): quickstart was broken cause of wrong data type. All other languages seem to expect a map so went with that. Signed-off-by: guergabo --- pub_sub/go/http/order-processor/app.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pub_sub/go/http/order-processor/app.go b/pub_sub/go/http/order-processor/app.go index 709357d96..3ee9344eb 100644 --- a/pub_sub/go/http/order-processor/app.go +++ b/pub_sub/go/http/order-processor/app.go @@ -18,7 +18,7 @@ type JSONObj struct { } type Result struct { - Data string `json:"data"` + Data map[string]int `json:"data"` } func getOrder(w http.ResponseWriter, r *http.Request) { @@ -49,7 +49,10 @@ func postOrder(w http.ResponseWriter, r *http.Request) { if err != nil { log.Fatal(err.Error()) } - fmt.Println("Subscriber received:", string(result.Data)) + for k, v := range result.Data { + d := fmt.Sprintf(`Subscriber received: {"%s":%d}`, k, v) + fmt.Println(d) + } obj, err := json.Marshal(data) if err != nil { log.Fatal(err.Error()) From b830b8dda5a6fd313aa2d8990dd1432a01c03fb9 Mon Sep 17 00:00:00 2001 From: guergabo Date: Wed, 14 Jun 2023 14:33:15 -0500 Subject: [PATCH 2/3] fix(go-http): requires content-type set to application/json Signed-off-by: guergabo --- pub_sub/go/http/checkout/app.go | 2 ++ pub_sub/go/http/order-processor/app.go | 1 + 2 files changed, 3 insertions(+) diff --git a/pub_sub/go/http/checkout/app.go b/pub_sub/go/http/checkout/app.go index 6fd216523..d19183691 100644 --- a/pub_sub/go/http/checkout/app.go +++ b/pub_sub/go/http/checkout/app.go @@ -34,6 +34,8 @@ func main() { log.Fatal(err.Error()) } + req.Header.Set("Content-Type", "application/json") + // Publish an event using Dapr pub/sub res, err := client.Do(req) if err != nil { diff --git a/pub_sub/go/http/order-processor/app.go b/pub_sub/go/http/order-processor/app.go index 3ee9344eb..9560a1468 100644 --- a/pub_sub/go/http/order-processor/app.go +++ b/pub_sub/go/http/order-processor/app.go @@ -45,6 +45,7 @@ func postOrder(w http.ResponseWriter, r *http.Request) { log.Fatal(err) } var result Result + fmt.Println(string(data)) err = json.Unmarshal(data, &result) if err != nil { log.Fatal(err.Error()) From 9e7d6e1e333b82d675d1feefeddb89ccefdc2a0d Mon Sep 17 00:00:00 2001 From: guergabo Date: Wed, 14 Jun 2023 14:35:52 -0500 Subject: [PATCH 3/3] refactor(cleanup) Signed-off-by: guergabo --- pub_sub/go/http/order-processor/app.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pub_sub/go/http/order-processor/app.go b/pub_sub/go/http/order-processor/app.go index 9560a1468..3ee9344eb 100644 --- a/pub_sub/go/http/order-processor/app.go +++ b/pub_sub/go/http/order-processor/app.go @@ -45,7 +45,6 @@ func postOrder(w http.ResponseWriter, r *http.Request) { log.Fatal(err) } var result Result - fmt.Println(string(data)) err = json.Unmarshal(data, &result) if err != nil { log.Fatal(err.Error())