This is an automated email from the ASF dual-hosted git repository.

ningyougang pushed a commit to branch support-array-result
in repository https://gitbox.apache.org/repos/asf/openwhisk-runtime-go.git

commit 597ad811ce7f55f2a83093fa9d586ee949258a25
Author: ning.yougang <[email protected]>
AuthorDate: Fri May 27 14:43:06 2022 +0800

    Support array result
---
 openwhisk/runHandler.go | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/openwhisk/runHandler.go b/openwhisk/runHandler.go
index 096eeeb..20be7a5 100644
--- a/openwhisk/runHandler.go
+++ b/openwhisk/runHandler.go
@@ -105,17 +105,28 @@ func (ap *ActionProxy) runHandler(w http.ResponseWriter, 
r *http.Request) {
 
        // check if the answer is an object map
        var objmap map[string]interface{}
+       var objarray []interface{}
+       var ismap = true
        err = json.Unmarshal(response, &objmap)
        if err != nil {
-               ap.theExecutor.logger <- "stop"
-               sendError(w, http.StatusBadGateway, "The action did not return 
a dictionary.")
-               return
+               ismap = false
+               err = json.Unmarshal(response, &objarray)
+               if err != nil {
+                       ap.theExecutor.logger <- "stop"
+                       sendError(w, http.StatusBadGateway, "The action did not 
return a dictionary or array.")
+                       return
+               }
        }
 
        // wait for log reading finished
        <-stopSignal
-       objmap[LOG_FIELD] = logs
-       newResponse, _ := json.Marshal(objmap)
+       var newResponse []byte
+       if ismap {
+               objmap[LOG_FIELD] = logs
+               newResponse, _ = json.Marshal(objmap)
+       } else {
+               newResponse, _ = json.Marshal(objarray)
+       }
 
        w.Header().Set("Content-Type", "application/json")
        w.Header().Set("Content-Length", fmt.Sprintf("%d", len(newResponse)))

Reply via email to