DonRichie commented on issue #161:
URL: 
https://github.com/apache/openwhisk-runtime-go/issues/161#issuecomment-1043697443


   **Here is my best try using a struct, but it fails due to the wrong function 
signature:**
   ```
   package main
   
   import (
     "fmt"
     "encoding/json"
   )
   
   type WhiskResponse struct {
     body string
     statusCode int
     headers map[string]interface{}
   }
   
   func PrettyPrint(v interface{}) (err error) {
         b, err := json.MarshalIndent(v, "", "  ")
         if err == nil {
                 fmt.Println(string(b))
         }
         return
   }
   
   func Main(inobj map[string]interface{}) map[string]interface{} {
     fmt.Println("inobj:")
     PrettyPrint(inobj)
     
     // assemble response
     resp := WhiskResponse{}
     resp.headers["Content-Type"] = "text/html"
     resp.statusCode = 201
     resp.body = "123"
     fmt.Println("resp:")
     PrettyPrint(resp)
     res, err := json.Marshal(resp)
     if err != nil {
       fmt.Println(err)
     }
     return string(res)
   }
   ```
   
   **error:**
   ```
   ./exec__.go:37:16: cannot use string(res) (type string) as type 
map[string]interface {} in return argument
   ```
   
   **error if changing function signature to "func Main(inobj 
map[string]interface{}) string {":**
   ```
   ./main__.go:56:9: cannot use Main (type func(map[string]interface {}) 
string) as type Action in assignment
   ```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to