From d2b4078b606374f5ab2fdc008f1af41dff1fe684 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 17 May 2017 16:38:23 -0700 Subject: [PATCH] Cleanup imports and errors --- fn/deploy.go | 5 ++++- fn/routes.go | 22 ++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/fn/deploy.go b/fn/deploy.go index ec3a4daa9..a98528363 100644 --- a/fn/deploy.go +++ b/fn/deploy.go @@ -154,7 +154,10 @@ func (p *deploycmd) route(c *cli.Context, ff *funcfile) error { routesCmd := routesCmd{client: apiClient()} rt := &models.Route{} - routeWithFuncFile(c, ff, rt) + + if err := routeWithFuncFile(c, ff, rt); err != nil { + return fmt.Errorf("error getting route with funcfile: %s", err) + } return routesCmd.patchRoute(c, p.appName, *ff.Path, rt) } diff --git a/fn/routes.go b/fn/routes.go index cb17ae7d9..260d883df 100644 --- a/fn/routes.go +++ b/fn/routes.go @@ -15,7 +15,6 @@ import ( fnclient "github.com/iron-io/functions_go/client" apiroutes "github.com/iron-io/functions_go/client/routes" - "github.com/iron-io/functions_go/models" fnmodels "github.com/iron-io/functions_go/models" "github.com/jmoiron/jsonq" "github.com/urfave/cli" @@ -247,7 +246,7 @@ func envAsHeader(req *http.Request, selectedEnv []string) { } } -func routeWithFlags(c *cli.Context, rt *models.Route) { +func routeWithFlags(c *cli.Context, rt *fnmodels.Route) { if i := c.String("image"); i != "" { rt.Image = i } @@ -287,7 +286,7 @@ func routeWithFlags(c *cli.Context, rt *models.Route) { } } -func routeWithFuncFile(c *cli.Context, ff *funcfile, rt *models.Route) error { +func routeWithFuncFile(c *cli.Context, ff *funcfile, rt *fnmodels.Route) error { var err error if ff == nil { ff, err = loadFuncfile() @@ -318,11 +317,14 @@ func (a *routesCmd) create(c *cli.Context) error { appName := c.Args().Get(0) route := cleanRoutePath(c.Args().Get(1)) - rt := &models.Route{} + rt := &fnmodels.Route{} rt.Path = route rt.Image = c.Args().Get(2) - routeWithFuncFile(c, nil, rt) + if err := routeWithFuncFile(c, nil, rt); err != nil { + return fmt.Errorf("error getting route info: %s", err) + } + routeWithFlags(c, rt) if rt.Path == "" { @@ -337,7 +339,7 @@ func (a *routesCmd) create(c *cli.Context) error { func (a *routesCmd) postRoute(c *cli.Context, appName string, rt *fnmodels.Route) error { - body := &models.RouteWrapper{ + body := &fnmodels.RouteWrapper{ Route: rt, } @@ -457,8 +459,12 @@ func (a *routesCmd) update(c *cli.Context) error { appName := c.Args().Get(0) route := cleanRoutePath(c.Args().Get(1)) - rt := &models.Route{} - routeWithFuncFile(c, nil, rt) + rt := &fnmodels.Route{} + + if err := routeWithFuncFile(c, nil, rt); err != nil { + return fmt.Errorf("error updating route: %s", err) + } + routeWithFlags(c, rt) err := a.patchRoute(c, appName, route, rt)