mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Display call ID for sync/async calls in CLI
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -21,6 +22,10 @@ func EnvAsHeader(req *http.Request, selectedEnv []string) {
|
||||
}
|
||||
}
|
||||
|
||||
type callID struct {
|
||||
CallID string `json:"call_id"`
|
||||
}
|
||||
|
||||
func CallFN(u string, content io.Reader, output io.Writer, method string, env []string) error {
|
||||
if method == "" {
|
||||
if content == nil {
|
||||
@@ -45,8 +50,14 @@ func CallFN(u string, content io.Reader, output io.Writer, method string, env []
|
||||
if err != nil {
|
||||
return fmt.Errorf("error running route: %s", err)
|
||||
}
|
||||
|
||||
io.Copy(output, resp.Body)
|
||||
if call_id, found := resp.Header["Fn_call_id"]; found {
|
||||
fmt.Fprint(output, fmt.Sprintf("Call ID: %v\n", call_id[0]))
|
||||
io.Copy(output, resp.Body)
|
||||
} else {
|
||||
c := &callID{}
|
||||
json.NewDecoder(resp.Body).Decode(c)
|
||||
fmt.Fprint(output, fmt.Sprintf("Call ID: %v\n", c.CallID))
|
||||
}
|
||||
|
||||
if resp.StatusCode >= 400 {
|
||||
// TODO: parse out error message
|
||||
|
||||
Reference in New Issue
Block a user