updated http provider

This commit is contained in:
2025-03-10 22:58:51 +01:00
parent edc7c1144d
commit e75fb0792e
2 changed files with 12 additions and 7 deletions

View File

@@ -8,7 +8,7 @@ def handle_task(task, output_dir):
try:
match task['type']:
case 'producer_nats':
case 'http_producer_nats':
__generate_producer(task, output_dir)
case 'processor_nats':
__generate_processor(task, output_dir)

View File

@@ -4,6 +4,7 @@ package main
import (
"fmt"
"net/http"
"io"
logger "gitea.rebus.ninja/lore/wasm-nats-producer-client/gen/wasi/logging/logging"
"gitea.rebus.ninja/lore/wasm-nats-producer-client/gen/wasmcloud/messaging/consumer"
@@ -30,14 +31,18 @@ func init() {
func handleHttp(w http.ResponseWriter, r *http.Request) {
// get body as string
if handleRequest(r.FormValue("data")) {
fmt.Fprintf(w, "Message sent!\n")
} else {
fmt.Fprintf(w, "Error\n")
value, err := io.ReadAll(r.Body)
if err != nil {
fmt.Fprintf(w, "Error, invalid request body\n")
return
}
// send response
if handleRequest(string(value)) {
fmt.Fprintf(w, "Message sent!\n")
} else {
fmt.Fprintf(w, "Error, coudln't send message\n")
}
}
func handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string]{