improve fn run/call http method support (#505)

This commit is contained in:
Jordan Krage
2017-02-01 14:46:27 -06:00
committed by Seif Lotfy سيف لطفي
parent e47d9540c6
commit f7a834d5ef
5 changed files with 37 additions and 17 deletions

View File

@@ -231,11 +231,19 @@ func (a *routesCmd) call(c *cli.Context) error {
u.Path = path.Join(u.Path, "r", appName, route)
content := stdin()
return callfn(u.String(), content, os.Stdout, c.StringSlice("e"))
return callfn(u.String(), content, os.Stdout, c.String("method"), c.StringSlice("e"))
}
func callfn(u string, content io.Reader, output io.Writer, env []string) error {
req, err := http.NewRequest("POST", u, content)
func callfn(u string, content io.Reader, output io.Writer, method string, env []string) error {
if method == "" {
if content == nil {
method = "GET"
} else {
method = "POST"
}
}
req, err := http.NewRequest(method, u, content)
if err != nil {
return fmt.Errorf("error running route: %v", err)
}