From dc2b40283e56d7d887f5530759a385f3ad5923db Mon Sep 17 00:00:00 2001 From: Makis Maropoulos Date: Fri, 3 Jun 2016 06:17:40 +0300 Subject: [PATCH] Iris cmd: download packages on every iris create command --- context/context.go | 2 ++ context_renderer.go | 7 +++++++ iris/main.go | 17 +++++++++++------ route.go | 5 +---- tests/router_test.go | 2 +- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/context/context.go b/context/context.go index 1524c6bb..a5aa1041 100644 --- a/context/context.go +++ b/context/context.go @@ -48,6 +48,8 @@ type ( HTML(status int, name string, binding interface{}, layout ...string) error // Render same as .HTML but with status to iris.StatusOK (200) Render(name string, binding interface{}, layout ...string) error + // MustRender same as .Render but returns 500 internal server http status (error) if rendering fail + MustRender(name string, binding interface{}, layout ...string) // RenderString accepts a template filename, its context data and returns the result of the parsed template (string) RenderString(name string, binding interface{}, layout ...string) (result string, err error) // MarkdownString parses the (dynamic) markdown string and returns the converted html string diff --git a/context_renderer.go b/context_renderer.go index 554bb6db..00e92086 100644 --- a/context_renderer.go +++ b/context_renderer.go @@ -43,6 +43,13 @@ func (ctx *Context) Render(name string, binding interface{}, layout ...string) e return ctx.HTML(StatusOK, name, binding, layout...) } +// MustRender same as .Render but returns 500 internal server http status (error) if rendering fail +func (ctx *Context) MustRender(name string, binding interface{}, layout ...string) { + if err := ctx.Render(name, binding, layout...); err != nil { + ctx.Panic() + } +} + // RenderString accepts a template filename, its context data and returns the result of the parsed template (string) func (ctx *Context) RenderString(name string, binding interface{}, layout ...string) (result string, err error) { return ctx.station.templates.RenderString(name, binding, layout...) diff --git a/iris/main.go b/iris/main.go index 351af0c4..8a160472 100644 --- a/iris/main.go +++ b/iris/main.go @@ -36,7 +36,7 @@ func init() { createCmd := cli.Command("create", "create a project to a given directory"). Flag("dir", "./", "-d ./ creates an iris starter kit to the current directory"). - Flag("type", "basic", "-t basic creates the project based on the t 'package'"). + Flag("type", "basic", "creates the project based on the -t package. Available type is only 'basic', currently"). Action(create) app.Command(createCmd) @@ -48,9 +48,15 @@ func main() { func create(flags cli.Flags) (err error) { - if !utils.DirectoryExists(packagesDir) { - downloadPackages() - } + /* ///TODO: add a version.json and check if the repository's version is bigger than local and then do the downloadPackages. + + if !utils.DirectoryExists(packagesDir) { + downloadPackages() + } + */ + + // currently: always download packages, because I'm adding new things to the packages every day. + downloadPackages() targetDir := flags.String("dir") @@ -97,10 +103,9 @@ func createPackage(packageName string, targetDir string) error { app.Printf("\n Failed to build the %s package. Trace: %s", packageName, err.Error()) } buildCmd.Wait() - println("\n") + print("\n\n") // run backend/backend(.exe) - executable := "backend" if runtime.GOOS == "windows" { executable += ".exe" diff --git a/route.go b/route.go index 44e11701..5e3b052c 100644 --- a/route.go +++ b/route.go @@ -172,11 +172,8 @@ func (r *Route) setHost(s string) { // Parse used to check arguments with the route's named parameters and return the correct url // second return value is false when the action cannot be done func (r *Route) Parse(args ...interface{}) (string, bool) { - // check if arguments are not equal to the named parameters ( : = 1, * = all named parameters split to / ), if this happens then send not found err - ///TODO: I'm thinking of making an option to disable these checks and just return a result, because they have cost when rendering an html/template, not too big compared to the render action but... we will see - // can also do a check if this url can be realy served (_tree.rootBranch.GetBranch(path, ctx.Params)) and if not then return a 404 or a link to a ./templates/errors/404.html - // but we don't have access to the context itself(so we will have some memory allocations), although it's a good idea but let's keep things simple here. argsLen := len(args) + // we have named parameters but arguments not given if argsLen == 0 && r.formattedParts > 0 { return "", false diff --git a/tests/router_test.go b/tests/router_test.go index 33beaa49..04e6e9fa 100644 --- a/tests/router_test.go +++ b/tests/router_test.go @@ -96,7 +96,7 @@ func TestRouter(t *testing.T) { }) // run the tests (1) - for idx, _ := range routes { + for idx := range routes { r := routes[idx] e.Request(r.Method, r.RequestPath). Expect().